0
アンドロイドアプリでFacebookログインを実装しようとしています。私はFacebookデベロッパーガイドに従っていますが、Facebookアプリがインストールされていないと、ログインの詳細が表示され、ログインして同じアクティビティにとどまり、ログアウトボタンが表示されます。アプリがインストールされていない場合、Facbookのログインは2番目のアクティビティを開始しません
public class MainActivity extends AppCompatActivity {
LoginButton loginButton;
CallbackManager callbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(getApplicationContext());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
isLoggedIn();
loginButton = (LoginButton) findViewById(R.id.login_button);
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
nextActivity(profile);
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
}
});
loginButton.setReadPermissions("user_friends");
}
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
super.onActivityResult(requestCode, responseCode, intent);
//Facebook login
callbackManager.onActivityResult(requestCode, responseCode, intent);
}
public void isLoggedIn() {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
if (accessToken!=null) {
Profile profile=Profile.getCurrentProfile();
nextActivity(profile);
}
}
private void nextActivity(Profile profile) {
if (profile != null) { Intent main = new Intent(MainActivity.this, Result.class);
main.putExtra("Name", profile.getFirstName());
main.putExtra("Surname", profile.getLastName());
startActivity(main);
finish();
}
}
}
はまだ – MateenSheikh
がするonSuccessグラムされているのと同じ問題を抱えて呼ばれるかどうか?あなたがaccesstokenとprofileのためにどんな価値を得ているのか?また、あなたが意図した "main"を初期化する場所は? – Rahil2952
はいonSuccessが呼び出されていて、プロファイルが** null **値を示していて、accesstokenが表示されています** {AccessTokenトークン:ACCESS_TOKEN_REMOVED権限:[user_friends、public_profile]} ** インテントはnextActivityメソッドで初期化されました。 。 – MateenSheikh