我想知道如何使用facebook令牌获取电子邮件和姓名?目前,它为所有字段返回null。我使用的是有效的非过期令牌。提前谢谢!
例如:
facebook_token = 'MY ACCESS TOKEN' # params[:facebook_token]
@user = FbGraph::User.me(facebook_token)
render :json=> @user, :status=>200
响应
{
"identifier":"me",
"endpoint":"https://graph.facebook.com/me",
"access_token":"MY ACCESS TOKEN",
"raw_attributes":
{
"access_token":"MY ACCESS TOKEN"
},
"cached_collections":{},
"name":null,
"first_name":null,
"middle_name":null,
"last_name":null,
"gender":null,
"locale":null,
"link":null,
"username":null,
"third_party_id":null,
"timezone":null,
"verified":null,
"about":null,
"bio":null,
"email":null,
"political":null,
"quotes":null,
"relationship_status":null,
"relationship":null,
"video_upload_limits":null,
"website":null,
"mobile_phone":null,
"installed":null,
"rsvp_status":null,
"security_settings":null,
"currency":null,
"religion":null,
"languages":[],
"education":[],
"interested_in":[],
"favorite_teams":[],
"work":[],
"devices":[],
"sports":[],
"favorite_athletes":[],
"inspirational_people":[]
}
答案 0 :(得分:2)
使用@user = FbGraph::User.me(facebook_token).fetch
然后,您将使用以下内容获取电子邮件和姓名。
user_email = @user.email
user_name = @user.name