4

我正在使用 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" });

我可以从 authResponse 获取 accessToken .... 它是一个长字符串。但 userID 字段的字面意思是“...”。我可以通过使用另一个图形 API 调用来获取额外的往返服务器来获取用户的 ID,/me但这似乎很浪费。

4

2 回答 2

6

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

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

这没有解释为什么 userID 字段"..."在登录响应对象中。但这是一种解决方法。

于 2012-05-23T18:31:51.607 回答
1

我在 github(https://github.com/davejohnson/phonegap-plugin-facebook-connect/issues/151)上发布了一个错误,因为这似乎是插件的“功能”。不确定问题出在 facebook IOS sdk(没有从 FB 传回这些数据)还是在插件中(没有在 JS 级别传回这些数据)。

于 2012-06-08T13:51:33.813 回答