response.authResponse is null

青春壹個敷衍的年華 提交于 2019-11-30 21:58:18

问题


i have write following code to check the login status of facebook.

    FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    var user_id = response.authResponse.userID;  
    var page_id = "app_id"; 
    var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
    var the_query = FB.Data.query(fql_query);
    the_query.wait(function(rows) {
                 if (rows.length == 1 && rows[0].uid == user_id) {
                    alert("liked the page");
                 }
                 else {
                    alert("not liked ");
                 }
            });
  }
  else if (response.status === 'not_authorized') {

  }
  else
  {
    alert("not logged in");
  }
});

i am getting the value for response.authResponse in first if section i.e. in if (response.status === 'connected') {} part but i'm getting response.authResponse null in else if (response.status === 'not_authorized') {} part,

do anyone have any idea about it??

Please help me.


回答1:


To be able to call the graph to get likes, you will need to have the user add/authenticate your app with the user_likes permissions and then you can read it. So in your code above, when they fall into either of the two else cases, call FB.login() (or display the fb login button on the page).

If you don't want to force the user to add/authenticate your app, then you will need to configure your app as a Page Tab app and then you can grab the signed_request (https://developers.facebook.com/docs/authentication/signed_request/) and decode that providing access to know if the user has liked the page that your app is a page tab of.




回答2:


The authResponse object is null if you're not connected... since you're haven't authorized this seems logical ...



来源:https://stackoverflow.com/questions/8758701/response-authresponse-is-null

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