无法从facebook javascript登录api获取userID

Wen*_*Wen 4 javascript facebook facebook-javascript-sdk phonegap-plugins cordova

我正在使用phonegap facebook插件和facebook 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" });
Run Code Online (Sandbox Code Playgroud)

我可以从authResponse获取accessToken ....它是一个长字符串.但是userID字段实际上是"......".我可以通过对服务器进行额外的往返来获取用户的ID,并使用另一个图形API调用来获取,/me但这似乎很浪费.

Leo*_*opd 6

[为了OP的利益]您可以在开始显示时通过额外调用服务器来获取客户端中的userID.这是正确的代码:

    FB.api('/me', function(me){
        if (me.id) {
            var facebook_userid = me.id;
            alert(facebook_userid);
        }
    });
Run Code Online (Sandbox Code Playgroud)

这并不能解释为什么userID字段"..."位于登录响应对象中.但这是一种解决方法.