Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook SDK for Python - Get user email

Prerequisite

  • My Facebook application have permissions to get user email
  • I've checked that getting user email with Javascript is working fine
  • Server has non-expired access token of user

Goal

  • Now, I'd like to do same task on server side with pythonforfacebook/facebook-sdk

Problem

  • Succeed to get name and id of user, but email is not included
  • I'd like to get email together

Code

import facebook

graph = facebook.GraphAPI(access_token='CAA...DZD')

graph.get_object(id='me')
# result : {u'name': u'Username', u'id': u'123456789'}

graph.get_object(id='me?fields=email,id,name')
# Error : facebook.GraphAPIError: An active access token must be used to query information about the current user
like image 675
Chemical Programmer Avatar asked Dec 19 '22 21:12

Chemical Programmer


1 Answers

You can try this code:

graph = facebook.GraphAPI(access_token)
profile = graph.get_object('me')
args = {'fields' : 'id,name,email', }
profile = graph.get_object('me', **args)
like image 190
vien vu Avatar answered Dec 21 '22 09:12

vien vu