I have the following code with urllib2 which prints HTTP Error 403: Forbidden but if I use urllib instead to fetch url, I don’t see any error and I do get a list of my friends. The access token used is same in both the cases.
url = 'https://graph.facebook.com/me/friends/'
params = {'access_token': 'a valid access-token...', 'fields': 'id,name,birthday'}
req = urllib2.Request(url, data=urllib.urlencode(params))
try:
con = urllib2.urlopen( req )
print con.read()
except Exception as excp:
print excp.read()
Please suggest what might be wrong.
This one is solved now. The trouble was that the request should be GET not POST and thus all the query parameters should be passed with url instead of being passed as POST data. So in my case the to get friends the code would look something like this:
Hope it helps someone.