FB.api('/me') always giving error code:2500 in phonegap android

我怕爱的太早我们不能终老 提交于 2019-12-20 06:05:50

问题


I am using facebook plugin to login and logout a user, which are working fine. The problem is when I request for the logged in user details using the function FB.api('/me'), it always gives the following error:

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

I used the debug mode to check PluginResult(pr) and JSONObject of the response. JSONObject contains the user information, which I required, I dont get where I am doing wrong.

  Plz help......

MY CODE:

           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);
                                         });
                   }
                   });

            }

回答1:


You need access token to retrieve more details than basic user information. Check that whether you have correct access token in Debug Tool to and ensure that you have all require permissions set permission.

Problem solved after changing the "session" in 'getResponse' method in ConnectPlugin to "authResponse"




回答2:


FB.api method is working fine for me to get the user details and post a feed to the facebook after I change the following method in ConnectPlugin.java as following.

  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();
}


来源:https://stackoverflow.com/questions/10026875/fb-api-me-always-giving-error-code2500-in-phonegap-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!