def renderPage(self): session = sessionmanager.getsession(self) msgtype = self.request.get('msgtype', None) if msgtype == 'index': indexname = self.request.get('indexname', None) value = self.request.get('value', None) if indexname == None or value == None: self.response.out.write("Error, wrong parameters.") logging.error("Unable to post to suer wall: wrong parameters.") return result = fbutils.fb_call("me/feed", {'access_token' : session['access_token'], 'message': 'I have just computed my ' + indexname + ' sociological index, its value is ' + value, 'name': 'Rorschach test platform', 'caption': indexname.title() + ' is a sociological index computed on the information present in FB. ' + conf.INDEXES[indexname] + '.', 'picture': fbutils.base_url(self) + 'smallgraph/' + session['me']['id'] + '/' + indexname, 'link': conf.base_url(self) + 'index/' + session['me']['id'] + '/' + indexname}, method='POST') if not 'id' in result: logging.error("Unable to post to the user wall: " + str(result)) elif msgtype == 'network': nodes = self.request.get('nodes', None) edges = self.request.get('edges', None) league = self.request.get('league', 'None').decode('utf-8') league = string.replace(league, ''', '\'') league = eval(league) i = 1 message = 'My Facebook network has ' + nodes + ' contacts and ' + edges + ' connections amongst them!\n' message += 'In my network the more influential contacts are:\n' for curuser in league: message += str(i) + '. ' + curuser[1] + '\n' i += 1 result = fbutils.fb_call("me/feed", {'access_token' : session['access_token'], 'message': message, 'name': 'My network elite group', 'caption': 'The elite group has been computed by Rorschach test platform with the information from your network of contatcs. For all your contacts information about their centrality has been computed using SNA. These information are about the role of influence and the number of connection of a friend within your network. Scoring these results, it has been possible to produce the list of the top influencers of your friends.', 'link': conf.base_url(self) + 'network/' + session['me']['id']}, method='POST') if not 'id' in result: logging.error("Unable to post to the user wall: " + str(result)) else: logging.error("Wrong msgtype parameter to postwall: " + str(msgtype)) self.response.out.write(json.dumps(result))
def getsession(self, access_token=None, redirect_uri=None): session = get_current_session() #try: try: if not access_token: access_token = fbutils.fbapi_auth(self, self.request.get('code'), redirect_uri)[0] fbutils.fb_call('me', args={'access_token': access_token}) except: session.terminate() return None try: if not session.is_active(): conf.BASE_URL = fbutils.base_url(self) session.regenerate_id() session.start() logging.info("Created a new session " + str(session)) me = fbutils.fb_call('me', args={'access_token': access_token}) if 'error' in me: raise Exception(me['error'['message']]) appid = fbutils.fb_call(conf.FBAPI_APP_ID, args={'access_token': access_token}) if 'error' in appid: raise Exception(appid['error'['message']]) app_token = fbutils.fbapi_get_application_access_token( self, redirect_uri) if 'error' in app_token: raise Exception(app_token['error'['message']]) roles = fbutils.get_user_roles(app_token, me['id']) if 'error' in roles: raise Exception(roles['error'['message']]) session['access_token'] = access_token session['me'] = me session['appid'] = appid session['app_token'] = app_token session['isdesktop'] = not bool( RE_MOBILE.search(get_user_agent(self.request))) session['roles'] = ['user'] if 'administrators' in (roles or []) or 'insights' in (roles or []): session['roles'].append('administrator') if 'administrators' in (roles or []): session['roles'].append('technician') session.save() except: session.terminate() return None return session