0

我正在使用 facebook 插件来登录和注销用户,这工作正常。问题是当我使用函数 FB.api('/me') 请求登录用户详细信息时,它总是给出以下错误:

      {"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500} 

我使用调试模式检查响应的 PluginResult(pr) 和 JSONObject。JSONObject 包含我需要的用户信息,我不知道我做错了什么。

  Plz help......

我的代码:

           function login() {
            FB.login(function(response) {
               if (response.session) {
                 console.log('Welcome!  Fetching your information.... ');
                 FB.api('/me', function(response) {
                   console.log('Good to see you, ' + JSON.stringify(response) + '.');
                 });
               } else {
                 console.log('User cancelled login or did not fully authorize.');
               }
             },{scope: 'email,user_likes'});
        }

       function logout() {
            FB.logout(function(response) {
                           console.log(localStorage.getItem("user_fb_log_status"));
                           localStorage.setItem("user_fb_log_status","LOGGED_OUT");

                      alert('logged out');
                      });
        }

The above code is working fine to login and logout the user. Below is the code i used to get the user details,

        function me() {
                FB.api('/me', { fields: 'id, name, picture' },  function(response) {
                   if (response.error) {
                   alert(JSON.stringify(response.error));
                   } else {
                   var data = document.getElementById('data');
                   fdata=response.data;
                   console.log("fdata: "+fdata);
                   response.data.forEach(function(item) {
                                         var d = document.createElement('div');
                                         d.innerHTML = "<img src="+item.picture+"/>"+item.name;
                                         data.appendChild(d);
                                         });
                   }
                   });

            }
4

2 回答 2

3

您需要访问令牌来检索比基本用户信息更多的详细信息。检查您是否在 调试工具中拥有正确的访问令牌,并确保您拥有所有需要权限设置权限

将 ConnectPlugin 中“getResponse”方法中的“会话”更改为“authResponse”后问题解决

于 2012-04-05T16:26:38.590 回答
1

在我更改 ConnectPlugin.java 中的以下方法后,FB.api 方法对我来说可以很好地获取用户详细信息并将提要发布到 facebook,如下所示。

  public JSONObject getResponse() {
    String response = "{" + "\"status\": \""
            + (facebook.isSessionValid() ? "connected" : "unknown") + "\","
            +
            // "\"session\": {" + "\"access_token\": \""
            // + facebook.getAccessToken() + "\"," + "\"expires\": \""
            // + facebook.getAccessExpires() + "\","
            // + "\"session_key\": true," + "\"sig\": \"...\","
            // + "\"uid\": \"" + this.userId + "\"" +

            "\"authResponse\": {" +

            "\"accessToken\": \"" + facebook.getAccessToken() + "\"," +

            "\"expiresIn\": \"" + facebook.getAccessExpires() + "\"," +

            "\"session_key\": true," +

            "\"sig\": \"...\"," +

            "\"userId\": \"" + this.userId + "\"" +

            "}" + "}";

    try {
        return new JSONObject(response);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return new JSONObject();
}
于 2012-04-16T06:26:56.583 回答