Facebook getLoginStatus () function and phone delay do not update status

I am currently developing an application on Android using phonegap and want to use Facebook in the application. I created a Facebook application called Test. When I do not enter the “Test”, but I am registered on Facebook (the Facebook application on the Android device) and run the getLoginStatus () function, I get an unknown response instead of not_authorized . So my first question is this? I wanted to get an unknown answer or is it a mistake from a telephone hell, and I should get a not_authorized answer.

The second question: when I enter the Facebook application called “test”, everything works as it should (a Facebook user logs in for the “test”). When I call the getLoginStatus () function, it works fine and says that I am connected without problems.

BUT

If I go to Facebook and delete the “test” application from my FB account and then run the Android application again and run the getLoginStatus () function, STILL says that I have the “test” application registered in my Facebook account, but it is not! Please note what I am doing in the code so that I call the server every time, and not use the cached result of the JS SDK. Now my second question. Is this supposed to happen? Or if this is not a Facebook or Phonegap problem (Phonegap either continues to receive a cached response, or Facebook does not update its side quickly enough?)

Here is the code:

 function getLoginStatus() { FB.getLoginStatus(function(response) { alert(JSON.stringify(response)); alert(response.status); if (response.status == 'connected') { alert('logged in'); FB.api('/me',function (response) { if (response.error) { alert('There is an error'); } else { alert(response.name); } }); } else { alert('not logged in'); } },true); } 

Any answer really like it!

+4
source share
2 answers

When I am not logged into "Test" but I am logged into Facebook (Facebook app on the Android device) and run the getLoginStatus() function I get a response of unknown instead of not_authorized.

not_authorized: you get not_authorized when a user logs in to facebook but doesn’t allow your application. If you transfer the guy to the main page of facebook, he enters the username and password and cancels the authorization, after which you are not authorized. If the guy is registered on facebook, and your application did not pass him fb for authorization, you are still not authorized

https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

unknown: If the user is not registered on facebook, you get the status of unknown.

So, logged in, not authorized: not_authorized Not authorized: unknown

If I go into Facebook and remove the app "test" from my FB account

I assume that it takes some time to change these changes. If the user has allowed the application in the current context, he will remain the authorizer for a while (or until he logs out). I do not think that something is personally wrong with this.

+4
source

This is not a telephone problem. unknown is one of the valid answers from the getLoginStatus function. For information on this feature, see the facebook API documentation . There they describe the unknown answer as:

the user is not currently logged in to Facebook and therefore we do not know whether they have authenticated your application or not (unknown)

As for your second question, the problem you see is because by default the getLoginStatus function caches its answer for performance reasons. However, they do provide you with the ability to force a status update. You can do this by passing a second Force parameter to getLoginStatus .

 FB.getLoginStatus(function(response) { // this will be called when the roundtrip to Facebook has completed }, true); // The second parameter, called 'force' by default is False. True signifies that you want to force a call to the server so you can see the latest login status. 

You can learn more about this Force parameter by looking at the link to this API link and find the "Force" parameter.

By the way, I temporarily deleted the answer, as I answered, not knowing how to answer the second question, but restored it after finding out the cause of your problem.

+2
source

Source: https://habr.com/ru/post/1493302/


All Articles