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.
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.
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