def do_async_call_to_cache_wall(accessToken ,user ,name , since): logging.info("Invocation async task") url = "https://graph.facebook.com/"+ user +"/home?access_token="+accessToken +"&limit=50" logging.info("Url 1 is " + url) fbUserWallContent = urlfetch.fetch(url,deadline=20,headers = { 'Cache-Control': 'no-cache,max-age=0', 'Pragma': 'no-cache' }) jsonData = json.loads(fbUserWallContent.content) if 'data' not in jsonData: logging.info("No data found in call for " + user + "/" + name + " using token " + accessToken) return data = jsonData['data'] fbmessages.processGraphApiJsonMessage(user ,name ,data, accessToken) allData = [] # Only retrieve this data if the user is new if (fbqueryuser.doesUserExist(user)): while 1: if 'paging' in jsonData: paging=jsonData['paging'] next = paging['next'] logging.info(next) url=next fbUserWallContent = urlfetch.fetch(url,deadline=20,headers = { 'Cache-Control': 'no-cache,max-age=0', 'Pragma': 'no-cache' }) jsonData = json.loads(fbUserWallContent.content) data = jsonData['data'] fbmessages.processGraphApiJsonMessage(user ,name ,data) if len(data) > 0: allData = allData + data logging.info("Data " + str(len(data)) + " all data " + str(len(allData))) else: logging.info(json.dumps(jsonData,sort_keys=True, indent=4)) break
def post(self): access_token = self.getToken() logging.info("This is the real time update post method being invoked") messageBody = self.request.body jsonData = json.loads(messageBody) logging.info(json.dumps(jsonData,sort_keys=True, indent=4)) data = jsonData['entry'] for i in data: fbUser = i['id'] who = fbqueryuser.getUserFullName(fbUser, access_token) logging.info("Whose wall changed " + who) #token = memcache.get(user+"long_lived") user = fbqueryuser.queryUserFromDataStore(fbUser) token = None if user is not None: token=user.long_lived_token if (token is not None): thisUsersWallUrl = "https://graph.facebook.com/"+ fbUser +"/home?access_token="+token+"&limit=99" logging.info(thisUsersWallUrl) fbUserWallContent = urlfetch.fetch(thisUsersWallUrl,deadline=20,headers = { 'Cache-Control': 'no-cache,max-age=0', 'Pragma': 'no-cache' }) wallData = json.loads(fbUserWallContent.content) if 'data' in wallData: data = wallData['data'] fbmessages.processGraphApiJsonMessage(fbUser ,who ,data, token) #logging.info(json.dumps(wallData,sort_keys=True, indent=4)) else: logging.info("User " + who + " does not have a long lived token")