我使用Facebook SDK 4.0,我的方案是:
我实现的代码是:
登录:
LoginManager.getInstance().logInWithReadPermissions(DashboardActivity.this,
Arrays.asList(FacebookUtils.FACEBOOK_READ_PERMISSION));
监听器:
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
if (chototProfile != null && !TextUtils.isEmpty(chototProfile.getAccountId())) {
connectFB(loginResult.getAccessToken().getToken());
}
LoginManager.getInstance().logInWithPublishPermissions(DashboardActivity.this,
Arrays.asList(FacebookUtils.FACEBOOK_PUBLISH_PERMISSION));//Request new permission.
}
@Override
public void onCancel() {
if (chototProfile != null && !TextUtils.isEmpty(chototProfile.getAccountId())
&& AccessToken.getCurrentAccessToken() != null) {
connectFB(AccessToken.getCurrentAccessToken().getToken());
}
}
@Override
public void onError(FacebookException error) {
Log.e(error);
}
});
问题为什么会发生以及如何解决?