当用户通过 facebook 撤销应用程序权限时,此代码应要求用户重新授权,但事实并非如此。有人能看出什么不对吗?“facebook”是一个 Facebook 对象。
public void facebookSetup() {
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null); //load an access token from sharedPreferences
long expires = mPrefs.getLong("access_expires", 0); //do the same for the token expiration time
if (access_token != null) { //if the access token exists in sharedPreferences, we'll use it
facebook.setAccessToken(access_token);
}
if (expires != 0) { //if the expiration time exists in shared preferences, use it
facebook.setAccessExpires(expires);
}
if (!facebook.isSessionValid()) {
facebook.authorize(this, new String[] { "email", "publish_stream", "user_photos", "publish_actions"}, new DialogListener() {
@Override
public void onComplete(Bundle values) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
}
}