Hi all
I am trying to get Facebook user url photo profile .
With google Api i can get from user['picture'] but can manage how get in
Facebook. It seem to be in the basic information from Facebook
documentation but i can' t manage to retrieve it
this is what i wrote in my module (not in model)
class FaceBookAccount(OAuthAccount):
"""OAuth impl for FaceBook"""
AUTH_URL="https://graph.facebook.com/oauth/authorize"
TOKEN_URL="https://graph.facebook.com/oauth/access_token"
def __init__(self,db,client_id,client_secret, session,request,response):
self.db = db
self.request = request
self.response = response
self.session = session
g = dict(GraphAPI=GraphAPI,
GraphAPIError=GraphAPIError,
request=request,
response=response,
session=session,
)
self.client_id = client_id,
self.client_secret = client_secret
OAuthAccount.__init__(self, g, client_id, client_secret,
self.AUTH_URL, self.TOKEN_URL,
scope='email',
state="auth_provider=facebook",
display='popup')
self.graph = None
def get_user(self):
'''Returns the user using the Graph API.
'''
if not self.accessToken():
return None
if not self.graph:
self.graph = GraphAPI((self.accessToken()))
user = None
try:
user = self.graph.get_object("me")
except GraphAPIError, e:
session.token = None
self.graph = None
if user:
if not user.has_key('username'):
username = user['id']
else:
username = user['username']
gender = 'M'
if user['gender'][0].lower() == 'f':
gender = 'F'
existent = self.db(self.db.auth_user.email ==
user["email"]).select(self.db.auth_user.id).first()
try:
data = user['picture']['data']['url']
except:
data = ''
if existent:
diz_account = dict(
gender = gender,
auth_login = 'Facebook',
url_img = user.get('picture', data),
birthdate = user.get('birthday', ''),
facebook_id = user['id'],
registration_id = user['id']
)
existent.update_record(**diz_account)
return dict(first_name = user.get('first_name',
user["name"].split()[0]),
last_name = user.get('last_name',
user["name"].split()[-1]),
username = user['email'],
email = user['email'],
gender = gender,
url_img = user.get('picture', ''),
auth_login = 'Facebook',
birthdate = user.get('birthday', ''),
facebook_id = user['id'],
registration_id = user['id']
)
else:
if not user.has_key('email'):
email = '%s.fakemail' %(user['id'])
else:
email = user['email']
return dict(first_name = user['first_name'],
last_name = user['last_name'],
username = '%s' %(email),
gender = gender,
url_img = user.get('picture', ''),
auth_login = 'Facebook',
birthdate = user.get('birthday', ''),
registration_id = user['id'],
email = '%s' %(email) )
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.