Facebook Oauth with Graph API不提供所有信息

时间:2015-09-22 02:42:47

标签: facebook facebook-graph-api oauth python-requests

我正在尝试实现一个非常基本的Oauth事务脚本(确切地说,这是一个:http://requests-oauthlib.readthedocs.org/en/latest/examples/facebook.html) 与Facebook通信并获取用户配置文件的用户信息。

我看过的大多数资源,包括facebook文档本身,都说默认访问请求包含“public_profile”的权限,其中包括“firstname”,“lastname”,“gender”,“age”等内容,也许不是那些东西,但是,很多东西。

然而,每次我进行交易时,我得到的只是“名字”和“身份证”。即使在graph.facebook.com上尝试不同的路线,我也能得到它。甚至更奇怪,当我在OAuth访问窗口中被问到权限时,我可以看到它要求'email'和'public_profile'的权限。

我找不到其他人遇到这个问题,我不知道出了什么问题。请帮忙。这是我的确切代码:

from requests_oauthlib import OAuth2Session
from requests_oauthlib.compliance_fixes import facebook_compliance_fix

# Credentials you get from registering a new application
client_id = '<id>'
client_secret = '<secret>'

# OAuth endpoints given in the Facebook API documentation
authorization_base_url = 'https://www.facebook.com/dialog/oauth'
token_url = 'https://graph.facebook.com/oauth/access_token'
redirect_uri = 'https://localhost:8080/'     # Should match Site URL
scope = [
    "email"
]

facebook = OAuth2Session(client_id, scope=scope, redirect_uri=redirect_uri)
facebook = facebook_compliance_fix(facebook)

# Redirect user to Facebook for authorization
authorization_url, state = facebook.authorization_url(authorization_base_url)
print 'Please go here and authorize,', authorization_url

# Get the authorization verifier code from the callback url
redirect_response = raw_input('Paste the full redirect URL here:')

# Fetch the access token
print "\naccess token: "
print facebook.fetch_token(
    token_url, 
    client_secret=client_secret, 
    authorization_response=redirect_response
)
print "\n"

# Fetch a protected resource, i.e. user profile
r = facebook.get('https://graph.facebook.com/me')
print r.content

1 个答案:

答案 0 :(得分:0)

WizKid是正确的。对于&gt; v2.4,必须明确指定他们想要的字段。 上面调用的适当替代是

r = facebook.get('https://graph.facebook.com/me?fields=id,first_name,last_name,picture,email,locale,timezone')

此问题的另一个版本可在此处找到:Facebook only returning name and id of user

不确定为什么在我在这个问题上所做的所有Google搜索后,ID都没有显示出来。

相关问题