2013-06-25 179 views
0

我想知道如何使用facebook令牌獲取電子郵件和名稱?目前它爲所有字段返回null。我正在使用有效的未過期令牌。提前致謝!如何通過訪問令牌獲取Facebook用戶信息?

如:

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":[] 
} 

回答

2

使用@user = FbGraph::User.me(facebook_token).fetch

然後你會得到的電子郵件和名稱使用以下。

user_email = @user.email 
user_name = @user.name 
相關問題