2015-12-16 115 views
5

所以我的項目遇到的一個問題是,通過谷歌登錄不一致工作。也就是說,它適用於我的朋友,而不是我的電腦,即使它在我擦拭手機(電話被損壞)之前昨天就工作過了。我們的登錄代碼是谷歌登錄的標準,問題是結果不斷返回假我認爲。驗證碼:谷歌登錄不工作android?

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.welcome_screen); 
     findViewById(R.id.sign_in_button).setOnClickListener(this); 

     GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
       .requestEmail() 
       .build(); 

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

     SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button); 
     signInButton.setSize(SignInButton.SIZE_STANDARD); 
     signInButton.setScopes(gso.getScopeArray()); 

    } 

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

private void signIn() { 
     Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
     startActivityForResult(signInIntent, RC_SIGN_IN); 
    } 

    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) { 
     if (result.isSuccess()) { 
      // Signed in successfully, show authenticated UI. 
      GoogleSignInAccount acct = result.getSignInAccount(); 

//   mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName())); 
      updateUI(acct); 
     } else { 
      // Signed out, show unauthenticated UI. 
      noUpdateUI(); 
     } 
    } 

    private void updateUI(GoogleSignInAccount acct) { 
     Intent intent = new Intent(getApplicationContext(), HomeScreen.class); 

     Bundle bundle = new Bundle(); 
     bundle.putSerializable("NEW_USER", new ClientUser(acct)); 
     intent.putExtras(bundle); 

     startActivity(intent); 
    } 


For some reason, the result is false: 

    private void noUpdateUI() { 
     System.out.println("**** Try again****"); 
//  mStatusTextView.setText(R.string.signed_out); 
     findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE); 
    } 

我想我已正確設置我的應用程序的憑據,因爲它從我的桌面曾任職之前我擦我的電話。值得注意的是,我的朋友在他的筆記本電腦上也有同樣的問題,但是他的桌面上沒有問題。不確定發生了什麼;有什麼建議麼?

日誌從sys.out:

12-16 18:48:43.282 27375-27375/oose2017.place2b D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN 
12-16 18:48:43.412 27375-27375/oose2017.place2b I/Timeline: Timeline: Activity_launch_request id:oose2017.place2b time:3231784 
12-16 18:48:43.452 27375-27375/oose2017.place2b D/Activity: performCreate Call Injection manager 
12-16 18:48:43.462 27375-27375/oose2017.place2b I/InjectionManager: dispatchOnViewCreated > Target : com.google.android.gms.auth.api.signin.internal.SignInHubActivity isFragment :false 
12-16 18:48:43.462 27375-27375/oose2017.place2b D/PhoneWindow: *FMB* installDecor mIsFloating : false 
12-16 18:48:43.462 27375-27375/oose2017.place2b D/PhoneWindow: *FMB* installDecor flags : 8454400 
12-16 18:48:43.462 27375-27375/oose2017.place2b D/SecWifiDisplayUtil: Metadata value : SecSettings2 
12-16 18:48:43.472 27375-27375/oose2017.place2b D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null 
12-16 18:48:43.472 27375-27375/oose2017.place2b D/PhoneWindow: *FMB* isFloatingMenuEnabled return false 
12-16 18:48:43.482 27375-27375/oose2017.place2b D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered! 
12-16 18:48:43.492 27375-27584/oose2017.place2b D/mali_winsys: new_window_surface returns 0x3000, [1440x2560]-format:1 
12-16 18:48:43.542 27375-27375/oose2017.place2b I/Timeline: Timeline: Activity_idle id: [email protected] time:3231916 
12-16 18:48:43.962 27375-27375/oose2017.place2b V/ActivityThread: updateVisibility : ActivityRecord{1458bd29 [email protected] {oose2017.place2b/oose2017.place2b.interfaces.Welcome.WelcomeScreen}} show : true 
12-16 18:48:43.962 27375-27375/oose2017.place2b V/ActivityThread: updateVisibility : ActivityRecord{d3e4299 [email protected] {oose2017.place2b/com.google.android.gms.auth.api.signin.internal.SignInHubActivity}} show : true 
12-16 18:48:48.102 27375-27375/oose2017.place2b I/System.out: ***** Try again!***** 
12-16 18:48:48.132 27375-27375/oose2017.place2b I/Timeline: Timeline: Activity_idle id: [email protected] time:3236507 
+0

只是爲了澄清,登錄窗口顯示正確嗎?然後,當你點擊登錄時,登錄失敗? – KodyVanRy

+0

@ DuhProgrammer13:是的,就是這樣。 – bianca

+0

在這個問題上有什麼牽引力?我在他們的示例代碼中也遇到了這個問題。 – bianca

回答

0

創建GoogleSignInOptions 這樣當

signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN). 
      requestScopes(new Scope(Scopes.EMAIL)). 
      requestEmail(). 
      requestIdToken(getString(R.string.client_id)). 
      build(); 
5

我有同樣的問題,你需要附上您的Android客戶端密鑰。 我解決它通過執行以下操作:

  1. 我去了我的build.gradle(APP),裏面defaultConfig和改變的applicationID我的包的名字(我不知道爲什麼它不是同最初)。 我從compile 'com.google.android.gms:play-services-auth:8.3.0'切換到compile 'com.google.android.gms:play-services-auth:8.4.0' 依賴

  2. 我產生了新的SHA-1鍵後確保apply plugin: 'com.google.gms.google-services'爲您的build.gradle(APP)即底部。要生成SHA-1密鑰,請在終端上粘貼:keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android 然後轉至您的credentials page並選擇您的項目。

  3. 在OAuth 2.0客戶端下,單擊您的Android客戶端密鑰。按照指示粘貼您生成的SHA-1密鑰和您的軟件包名稱。點擊保存。

    1. 下載一個新的google-services.json文件並將其粘貼到您的應用程序/目錄中。

然後再次嘗試登錄。希望它能工作。 欲瞭解更多信息,請參閱此postthis as well。它幫我解決了我的問題

+0

積分3和4是我的問題。謝謝你 –

+0

歡迎你。樂意效勞 – NezSpencer