我正在使用AccessTokenTracker让我的应用程序了解在线发生的任何权限更改,例如通过笔记本电脑。
Secanario:该应用程序登录到我的FB并获得对" publish_actions的访问权限 &#34 ;.如果用户正在删除" publish_actions"使用他的笔记本电脑或任何其他设备的权限,然后我的AccessTokenTracker没有使用最新的权限集更新。因此代码总是达到
System.out.println("FB already has publish_actions");
如果我要在其他设备中更新我的应用的权限,它会在accessTokenTracker中更新吗?如果是这样,为什么我的情况没有得到更新?
private AccessTokenTracker accessTokenTracker;
private AccessToken currentAccessToken;
@Override
protected void onCreate (Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
System.out.println("FacebookCallback : Success");
fbShareNow();
}
@Override
public void onCancel() {
// App code
System.out.println("FacebookCallback : Cancel");
}
@Override
public void onError(FacebookException exception) {
// App code
System.out.println("FacebookCallback : Erroe");
}
});
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken newAccessToken) {
currentAccessToken=newAccessToken;
}
};
currentAccessToken = AccessToken.getCurrentAccessToken();
}
@Override
public void onDestroy() {
super.onDestroy();
accessTokenTracker.stopTracking();
}
@Override
public void facebookShare(String msg) {
if (currentAccessToken != null) {
System.out.println("FB already logged in");
if(currentAccessToken.getPermissions().contains("publish_actions")){
System.out.println("FB already has publish_actions");
fbShareNow();
} else{
System.out.println("FB has no publish_actions");
}
}else {
System.out.println("FB not logged in");
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
}
}