def parse_publication(self, fbid, since="", until="", limit=50): # fbid : Facebook ID of the user we want to parse # since : Date to crawl since (use unixtime) (OPTIONAL) # until : Date to crawl until (use unixtime) (OPTIONAL) # limit : How many publications to get by request. Max. 5000 (OPTIONAL) params = [self.__access_token, "limit=" + str(limit)] if since != "": params.append("since=" + since) if until != "": params.append("until=" + until) completeurl = urlcreator("https", self.__api_url, fbid + r"/feed", params) msg = backoff(completeurl, self.__attemps) response = json.loads(msg) data = {} # objectfor variables 'data' and 'paging' data["data"] = [] if "data" in response: x = 0 for i in response["data"]: data["data"].append({}) data["data"][x]["id"] = i["id"] data["data"][x]["from"] = i["from"]["id"] data["data"][x]["type"] = i["type"] data["data"][x]["time"] = i["created_time"] data["data"][x]["comments"] = i["comments"]["count"] if "likes" in i: data["data"][x]["likes"] = i["likes"]["count"] else: data["data"][x]["likes"] = 0 if "link" in i: data["data"][x]["link"] = i["link"] else: data["data"][x]["link"] = r"http://www.facebook.com/" + data["data"][x]["from"] if "message" in i: data["data"][x]["message"] = i["message"] else: data["data"][x]["message"] = i["type"] self.__num_feeds += 1 x += 1 if "paging" in response: # There's more pages for this request data["paging"] = response["paging"] else: data["paging"] = {} return data
def batch_request(self, json_array): # json_array : Json array which contains all the requests for doing a batch request. msg = backoff( r"https://" + self.__api_url + r"/?batch=" + json.dumps(json_array) + r"&" + self.__access_token + r"&method=post", self.__attemps, ) response = json.loads(msg) res = [] for i in range(len(response)): res[i] = {} if response[i]["code"] == 200: res[i]["id"] = response[i]["body"]["id"] res[i]["name"] = response[i]["body"]["name"] res[i]["gender"] = response[i]["body"]["gender"] res[i]["locale"] = response[i]["body"]["locale"] return res
def parse_user(self, userid): # userid : Facebook User ID msg = backoff(r"http://graph.facebook.com/" + userid, self.__attemps) response = json.loads(msg) return response