Error Validating Access Token: The User Has Not Authorized Application. Facebook Sdk 4
Here is the case : If I previously granted read permissions to my application via LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList('email')); Then, when I n
Solution 1:
Just do something like:
@OverridepublicvoidonError(FacebookException error) {
Timber.e(error, "Error during facebook login");
AccessToken.setCurrentAccessToken(null);
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"))
}
Solution 2:
Calling AccessToken.refreshCurrentAccessTokenAsync()
worked for me. I get the error in the implementation of FacebookCallback.onError()
, where I call
AccessToken.refreshCurrentAccessTokenAsync()
which clears the access token in Facebook SDK.
Because this is an async call, I cannot call loginManager.logInWithReadPermissions()
immediately; There is no callback, so I display an AlertDialog
to the user and when the user clicks "OK", at that time I call loginManager.logInWithReadPermissions()
.
So user experience is not too bad, and it is acceptable for an edge case.
Solution 3:
To do a correct validation check the accesstoken if it is null or expired:
AccessTokenaccessToken= AccessToken.getCurrentAccessToken();
booleanisLoggedIn= accessToken != null && !accessToken.isExpired();
if (isLoggedIn) {
//Post Facebook.
} else {
manager.logIn(shareAct, Arrays.asList("public_profile"));
}
Post a Comment for "Error Validating Access Token: The User Has Not Authorized Application. Facebook Sdk 4"