2017-12-17 4 views
0

私のアプリにGoogleのログインボタンが動作していないという問題があります。 ここに問題があるのは、私が追加したfacebookの機能だからです。Facebookのボタンを追加した後にgoogleのサインインボタンが機能しない

FacebookSdk.sdkInitialize(getApplicationContext()); 
    setContentView(R.layout.activity_gesta_main); 
    mCallbackManager = CallbackManager.Factory.create(); 
    LoginButton mLoginButton = (LoginButton) findViewById(R.id.login_button); 

    mLoginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() { 
     @Override 
     public void onSuccess(LoginResult loginResult) { 
      String userLoginId = loginResult.getAccessToken().getUserId(); 
      Intent facebookIntent = new Intent(GestaMainActivity.this, Facebook_login.class); 
      Profile mProfile = Profile.getCurrentProfile(); 
      String firstName = mProfile.getFirstName(); 
      String lastName = mProfile.getLastName(); 
      String userId = mProfile.getId().toString(); 
      String profileImageUrl = mProfile.getProfilePictureUri(96, 96).toString(); 

      facebookIntent.putExtra(PROFILE_USER_ID, userId); 
      facebookIntent.putExtra(PROFILE_FIRST_NAME, firstName); 
      facebookIntent.putExtra(PROFILE_LAST_NAME, lastName); 
      facebookIntent.putExtra(PROFILE_IMAGE_URL, profileImageUrl); 
      startActivity(facebookIntent); 

     } 

     @Override 
     public void onCancel() { 
     } 

     @Override 
     public void onError(FacebookException error) { 
     } 

この問題を解決する方法はあります:私は上の作成方法からこの機能を削除すると におけるGoogleの記号は、これはすべての問題をcuase方法であり、うまく働きましたか?

これは私のmainActivityです:

public class GestaMainActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener{ 
private SignInButton btnLogin; 
private GoogleSignInOptions googleSignInOptions; 
private GoogleApiClient googleApiClient; 
private ProgressDialog mConnectionProgressDialog; 
private static final int REQUEST_CODE_LOGIN = 10; 

public static final String PROFILE_GOOGLE = "PROFILE_FIRST_NAME"; 
public static final String PROFILE_GOOGLE_EMAIL = "PROFILE_LAST_NAME"; 
public static final String PROFILE_GOOGLE_IMAGE_URL = "PROFILE_IMAGE_URL"; 

LoginButton mLoginButton; 
private CallbackManager mCallbackManager; 
public static final String PROFILE_USER_ID = "USER_ID"; 
public static final String PROFILE_FIRST_NAME = "PROFILE_FIRST_NAME"; 
public static final String PROFILE_LAST_NAME = "PROFILE_LAST_NAME"; 
public static final String PROFILE_IMAGE_URL = "PROFILE_IMAGE_URL"; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_gesta_main); 
    setTitle("Gesta App"); 

    googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestProfile().build(); 
    googleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, this) 
      .addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions).addApi(Plus.API).build(); 

    btnLogin = (SignInButton) findViewById(R.id.signin_button_google); 
    btnLogin.setSize(SignInButton.SIZE_STANDARD); 
    btnLogin.setScopes(googleSignInOptions.getScopeArray()); 

    btnLogin.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Intent signin = Auth.GoogleSignInApi.getSignInIntent(googleApiClient); 
      startActivityForResult(signin, REQUEST_CODE_LOGIN); 
     } 
    }); 

    FacebookSdk.sdkInitialize(getApplicationContext()); 
    setContentView(R.layout.activity_gesta_main); 
    mCallbackManager = CallbackManager.Factory.create(); 
    LoginButton mLoginButton = (LoginButton) findViewById(R.id.login_button); 

    mLoginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() { 
     @Override 
     public void onSuccess(LoginResult loginResult) { 
      String userLoginId = loginResult.getAccessToken().getUserId(); 
      Intent facebookIntent = new Intent(GestaMainActivity.this, Facebook_login.class); 
      Profile mProfile = Profile.getCurrentProfile(); 
      String firstName = mProfile.getFirstName(); 
      String lastName = mProfile.getLastName(); 
      String userId = mProfile.getId().toString(); 
      String profileImageUrl = mProfile.getProfilePictureUri(96, 96).toString(); 

      facebookIntent.putExtra(PROFILE_USER_ID, userId); 
      facebookIntent.putExtra(PROFILE_FIRST_NAME, firstName); 
      facebookIntent.putExtra(PROFILE_LAST_NAME, lastName); 
      facebookIntent.putExtra(PROFILE_IMAGE_URL, profileImageUrl); 
      startActivity(facebookIntent); 

     } 

     @Override 
     public void onCancel() { 
     } 

     @Override 
     public void onError(FacebookException error) { 
     } 

    }); 
    mConnectionProgressDialog = new ProgressDialog(this); 
    mConnectionProgressDialog.setMessage("Signing in...");} 

protected void onActivityResult(int requestcode, int resultcode, Intent data) 
{ 
    super.onActivityResult(requestcode,resultcode,data); 

    mCallbackManager.onActivityResult(requestcode, resultcode, data); 
    if (requestcode==REQUEST_CODE_LOGIN) 
    { 
     GoogleSignInResult googleSignInResult = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
     GoogleSignInAccount account = googleSignInResult.getSignInAccount(); 
     Person profile = Plus.PeopleApi.getCurrentPerson(googleApiClient); 

     try { 
      Intent sendData = new Intent(GestaMainActivity.this,Google_Gesta.class); 
      String name, email, dpurl; 
      name = account.getDisplayName(); 
      email = account.getEmail(); 
      dpurl = account.getPhotoUrl() != null ? account.getPhotoUrl().toString() : null; 
      sendData.putExtra(PROFILE_GOOGLE,name); 
      sendData.putExtra(PROFILE_GOOGLE_EMAIL,email); 
      sendData.putExtra(PROFILE_GOOGLE_IMAGE_URL,dpurl); 

      startActivity(sendData); 

     }catch (Exception e) 
     { 
      Toast.makeText(GestaMainActivity.this,e.getMessage(),Toast.LENGTH_SHORT).show(); 
     } 

    }else{ 
     Toast.makeText(GestaMainActivity.this,"Login Failed",Toast.LENGTH_LONG); 
    } 
} 


@Override 
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { 

} 

@Override 
protected void onResume() { 
    super.onResume(); 

    AppEventsLogger.activateApp(this); 

} 

@Override 
protected void onPause() { 
    super.onPause(); 
    AppEventsLogger.deactivateApp(this); 
} 

答えて

0

Plus.PeopleApi.getCurrentPerson(googleApiClient);が廃止されます。 あなたがここに

+0

から

GoogleSignInAccount account = googleSignInResult.getSignInAccount(); 

からすべての情報を得ることができます私は、コールバックメソッドへのtry/catchを追加することによってこの問題を解決しました –

関連する問題