经许可实施facebook登录,那个时间执行无限循环的原因,我无法理解。我根据facebook devloper方面的给定步骤实现,我的代码是在。
下给出的mFacebookCallbackManager = CallbackManager.Factory.create();
fbLoginButton = (LoginButton) findViewById(R.id.fbLoginButton);
fbLoginButton.setPublishPermissions(PrefrennceList.FB_PUBLISH_PERMISSION);
fbLoginButton.registerCallback(mFacebookCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Utility.storeString(mPreferences, PrefrennceList.FB_ACCESSTOKEN, loginResult.getAccessToken().getToken());
Utility.storeString(mPreferences, PrefrennceList.FB_USER_ID, loginResult.getAccessToken().getUserId());
LoginManager.getInstance().logInWithReadPermissions(SocialLoginActivity.this, PrefrennceList.FB_READ_PERMISSION);
return;
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
error.printStackTrace();
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data);
}
答案 0 :(得分:0)
您在logInWithReadPermissions()
回调中添加了onSuccess()
方法。删除它并在之前添加,如下所示
mFacebookCallbackManager = CallbackManager.Factory.create();
fbLoginButton = (LoginButton) findViewById(R.id.fbLoginButton);
fbLoginButton.setPublishPermissions(PrefrennceList.FB_PUBLISH_PERMISSION);
LoginManager.getInstance().logInWithReadPermissions(SocialLoginActivity.this, PrefrennceList.FB_READ_PERMISSION);
fbLoginButton.registerCallback(mFacebookCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Utility.storeString(mPreferences, PrefrennceList.FB_ACCESSTOKEN, loginResult.getAccessToken().getToken());
Utility.storeString(mPreferences, PrefrennceList.FB_USER_ID, loginResult.getAccessToken().getUserId())
return;
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
error.printStackTrace();
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data);
}