Question

I am very new to the Graph API and a basically trying to write a python (v2.7) script which takes as input the userID of a Facebook user and returns names/IDs of all groups/pages that have been liked by the user.

I have managed to acquire an Access Token that uses the following permissions: user_likes and user_groups. Do I need anything else?

I have used the following code so far to get a JSON dump of all the output from this access token:

import urllib
import json
import sys
import os

accessToken = 'ACCESS_ToKEN_HERE'  #INSERT YOUR ACCESS TOKEN
userId = sys.argv[1]          
limit=100

# Read my likes as a json object
url='https://graph.facebook.com/'+userId+'/feed?access_token='+accessToken +'&limit='+str(limit)
data = json.load(urllib.urlopen(url))
id=0

print str(data)

I did get some JSON data but I couldn't find any page/group related info in it neither did it seem to be the most recently updated data! Why is this?

Also, what are the field names that must be tracked to detect a page or a group in the likes data? Please help!

Was it helpful?

Solution

You are using the wrong API- /feed - this will fetch the feeds/posts of the user, not the pages/groups.

To get the groups he has joined:

API: /{user-id}/groups
Permissions req: user_groups

To get the pages he has liked:

API: /{user-id}/likes
Permissions req: user_likes

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top