2017-08-04 95 views
0

我的應用程序需要通過Google登錄。我從firebase打開了該教程(但首先您需要配置Google本身)是否按照說明編寫。但是,它不起作用。爲什麼result.isSuccess()總是爲false。因此,我無法獲取帳戶信息。我無法通過Google登錄獲取帳戶信息

的logcat:

08-04 08:32:28.128 1948 1948 D  AutoManageHelper        starting AutoManage for client 0 false false 
08-04 08:32:28.136 1948 1948 D  AutoManageHelper        onStart true {[email protected]} 
08-04 08:32:28.296 1948 1974 E  GED           Failed to get GED Log Buf, err(0) 
08-04 08:32:35.293 1948 1948 D  Tag           handleSignInResult:false 

代碼:

import android.content.*; 
import android.os.*; 
import android.support.v7.app.*; 
import android.view.*; 
import android.view.View.*; 
import com.google.android.gms.auth.api.*; 
import com.google.android.gms.auth.api.signin.*; 
import com.google.android.gms.common.api.*; 
import android.util.*; 
import android.support.v4.app.*; 
import com.google.android.gms.common.*; 
import android.widget.*; 

public class GoogleSigInActivity extends FragmentActivity implements GoogleApiClient.OnConnectionFailedListener 
{ 

    GoogleApiClient mGoogleApiClient; 
    private static final int RC_SIGN_IN = 9001; 
    private String TAG = "Tag"; 
    TextView mStatusTextView; 
    @Override 
    public void onConnectionFailed(ConnectionResult p1) 
    { 
     // TODO: Implement this method 
    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_gogle_sign_in); 
     GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN). 
      requestEmail(). 
      build(); 

     // Build a GoogleApiClient with access to the Google Sign-In API and the 
     // options specified by gso. 

     mGoogleApiClient = new GoogleApiClient.Builder(this). 
      enableAutoManage(this, this). 
      addApi(Auth.GOOGLE_SIGN_IN_API, gso). 
      build(); 

     mStatusTextView = (TextView) findViewById(R.id.activitygoglesigninTextView1); 

     findViewById(R.id.sign_in_button).setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View p1) 
       { 
        switch (p1.getId()) 
        { 
         case R.id.sign_in_button : 
          signIn(); 
          break; 
        } 
       } 
      }); 
    } 

    private void signIn() 
    { 

     Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
     startActivityForResult(signInIntent, RC_SIGN_IN); 
    } 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) 
    { 
     super.onActivityResult(requestCode, resultCode, data); 

     // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); 
     if (requestCode == RC_SIGN_IN) 
     { 
      GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
      handleSignInResult(result); 
     } 
    } 

    private void handleSignInResult(GoogleSignInResult result) 
    { 

     Log.d(TAG, "handleSignInResult:" + result.isSuccess()); 


     if (result.isSuccess()) 
     { 
      // Signed in successfully, show authenticated UI. 
      GoogleSignInAccount acct = result.getSignInAccount(); 
      mStatusTextView.setText("work " + acct.getDisplayName()); 
     } 
     else 
     { 
      // Signed out, show unauthenticated UI. 
      mStatusTextView.setText("not work"); 
     } 
    } 


} 

回答

0

你應該先檢查是否從您API console啓用了 「谷歌Play遊戲服務」 API。這使您的應用可以使用身份驗證服務。 對我來說,谷歌登錄只適用於我的應用程序的簽名APK,不能使它在調試版本中工作。

+0

謝謝,我會試試看) –

相關問題