The following python code:
# user profile information
args = {
'access_token':access_token,
'fields':'id,name',
}
print 'ACCESSED', urllib.urlopen('https://graph.facebook.com/me', urllib.urlencode(args)).read()
Prints the following:
ACCESSED {“success”:true}
The token is valid, no error, the fields are valid. Why is it not returning the fields I asked for?
2
Answers
Turns out urllib.urlopen will send the data as a POST when the data parameter is provided. Facebook Graph API works using GET not POST. Change the call to trick the function into calling just a URL ( no data ):
And everything works! Sigh, I can see why urllib is being altered in python 3.0...
You have to add a
/
to the URL to gethttps://graph.facebook.com/me/
instead ofhttps://graph.facebook.com/me
.PS : Try using the
requests
which is much more efficient thanurllib
, here is the doc : http://docs.python-requests.org/en/master/