GAE and Facebook Connect: How to get age and gende

2019-06-01 08:41发布

I'm working with Google App Engine and Facebook Connect.

I have found Facebook Python SDK at https://github.com/facebook/python-sdk/tree/master/examples/appengine and it has some examples for basic user login and getting their names and friends.

How can I get the user's other information? I would like to have their age and gender for my app to work properly. I know it requires additional permissions to get that information but how do I do that?

1条回答
手持菜刀,她持情操
2楼-- · 2019-06-01 08:52

You dont need any permission for Gender property of the user and for the Age you can calculate by Subtracting the User's Date of birth by current Date.

For Date of Birth you need user_birthday Extended Permission

If you want to know how to request permissions specify them in scope query parameter like this

https://graph.facebook.com/oauth/authorize?
 client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=user_birthday

Check out the example here on github https://github.com/facebook/python-sdk/blob/master/examples/appengine/example.py

I dont know python myself but, If you are using the python sdk then you can request user information like this (inferred from the example above)

profile = graph.get_object("me")
gender = profile["gender"]
dateofbirth = profile["birthday"]

now you can get age by subtracting user date from current date.

查看更多
登录 后发表回答