Sadly this is because of the poor documentation of the SDK by FaceBook.
You have to set a tracker for AccessToken
, similar to what you'd do with Profile
.
My code for that is as below:
private AccessTokenTracker mAccessTokenTracker;
private void loginToMyFbApp() {
FacebookSdk.sdkInitialize(this);
if (AccessToken.getCurrentAccessToken() != null) {
mAccessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
mAccessTokenTracker.stopTracking();
if(currentAccessToken == null) {
//(the user has revoked your permissions -
//by going to his settings and deleted your app)
//do the simple login to FaceBook
}
else {
//you've got the new access token now.
//AccessToken.getToken() could be same for both
//parameters but you should only use "currentAccessToken"
}
}
};
AccessToken.refreshCurrentAccessTokenAsync();
}
else {
//do the simple login to FaceBook
}
}
Edit
Removed startTracking()
call as rightly pointed out by Astrount in the comment below.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…