4

我正在使用phonegap facebook插件和facebook javascript api。这里是我的代码无法从facebook获取用户ID javascript登录api

FB.init({ 
    appId: "xxxxxxxxxxxxxxx", 
    status: true, 
    oauth :true, 
    nativeInterface: CDV.FB, 
    //channelURL : 'www', // Channel File 
    cookie: true, 
    //useCachedDialogs: false, 
    xfbml: true 
}); 

FB.login(function(response) { 
    if (response.authResponse) { 
     alert(response.authResponse.userID); // literally shows three dots 
     FB.api('/me', function(me){ 
      if (me.id) { 
       alert(me.id); // this works 
      } 
     }); 
    } 
}, { scope: "email" }); 

我可以从authResponse获得accessToken ....它是一个长字符串。但userID字段实际上是“...”。我可以通过使用另一个图形API调用向服务器额外往返获取用户ID,以获取/me,但这看起来很浪费。

+0

我看到同样的事情。请注意,oauth令牌在回调中有效,但userID字段实际上是“...” – Leopd

+0

是不是通过“response.authResponse.userID”语句获得用户ID? – MSUH

+1

问题并不清楚,我相信我也有同样的问题,所以我要澄清我看到的确切问题的问题。 – Leopd

回答

6

[为了OP的好处]您可以通过在开始显示时向服务器额外呼叫来获取客户端中的用户ID。下面是正确的代码:

FB.api('/me', function(me){ 
     if (me.id) { 
      var facebook_userid = me.id; 
      alert(facebook_userid); 
     } 
    }); 

这并不能解释为什么用户ID字段是登录响应对象"..."。但这是一种解决方法。

+0

我该如何在html页面中使用它。你可以帮我吗? –

+0

为我工作...谢谢你 –

相关问题