2016-11-12 69 views
12

我知道這個問題已被許多人問及已被回答。谷歌Firebase登錄狀態12501(不工作),在發佈構建變體和jks SHA

那麼,爲什麼我又問這個問題呢?因爲我嘗試了這些解決方案,並且我確實遵循了Google文檔,遵循教程和YouTube。仍然沒有運氣。

好吧,這就是我在我的項目中所做的。

項目: GoogleSignIn

dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.0' 
     classpath 'com.google.gms:google-services:3.0.0' 
     } 

搖籃(模塊:APP)

apply plugin: 'com.android.application' 

android { 
    signingConfigs { 
     config { 
      keyAlias 'alias' 
      keyPassword 'keypass' 
      storeFile file('/home/reoxey/path/to/jks') 
      storePassword 'storepass' 
     } 
    } 
    compileSdkVersion 25 
    buildToolsVersion "25.0.0" 
    defaultConfig { 
     applicationId "reoxey.com.googlesignin" 
     minSdkVersion 19 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      signingConfig signingConfigs.config 
     } 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:25.0.0' 
    compile 'com.android.support:design:25.0.0' 
    compile 'com.google.firebase:firebase-auth:9.8.0' 
    compile 'com.google.android.gms:play-services-auth:9.8.0' 
    testCompile 'junit:junit:4.12' 
} 

apply plugin: 'com.google.gms.google-services' 

LoginActivity.java

gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
       .requestIdToken(getString(R.string.web_client_key)) 
       .requestEmail() 
       .build(); 

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

     findViewById(R.id.sign_in_button).setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
       startActivityForResult(signInIntent, RC_SIGN_IN); 
      } 
     }); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if (requestCode == RC_SIGN_IN){ 
      GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
      if (result.isSuccess()){ 
       Toast.makeText(getApplicationContext(),"Nailed it",Toast.LENGTH_LONG).show(); 
      }else { 
       Snackbar.make(mLoginFormView,result.getStatus().toString(),Snackbar.LENGTH_LONG).show(); 
       Toast.makeText(getApplicationContext(),"Messed",Toast.LENGTH_LONG).show(); 

      } 
     } 
    } 

string.xml

<string name="web_client_key">123456789-clientwebapplication.apps.googleusercontent.com</string> 

清單中沒有特別的配置,我相信我不會錯過任何東西。

谷歌,services.json

{ 
    "project_info": { 
    "project_number": "{numeric-id}", 
    "firebase_url": "https://project--123456789.firebaseio.com", 
    "project_id": "project--123456789", 
    "storage_bucket": "project--123456789.appspot.com" 
    }, 
    "client": [ 
    { 
     "client_info": { 
     "mobilesdk_app_id": "1:{numeric-id}:android:sfdjgsdkdfgsfs", 
     "android_client_info": { 
      "package_name": "reoxey.com.googlesignin" 
     } 
     }, 
     "oauth_client": [ 
     { 
      "client_id": "{numeric-id}-androidkey.apps.googleusercontent.com", 
      "client_type": 1, 
      "android_info": { 
      "package_name": "reoxey.com.googlesignin", 
      "certificate_hash": "{sha1-from-jks-file}" 
      } 
     }, 
     { 
      "client_id": "{numeric-id}-webapplication.apps.googleusercontent.com", 
      "client_type": 3 
     } 
     ], 
     "api_key": [ 
     { 
      "current_key": "{android-key}" 
     } 
     ], 
     "services": { 
     "analytics_service": { 
      "status": 1 
     }, 
     "appinvite_service": { 
      "status": 2, 
      "other_platform_oauth_client": [ 
      { 
       "client_id": "{numeric-id}-webapplication.apps.googleusercontent.com", 
       "client_type": 3 
      } 
      ] 
     }, 
     "ads_service": { 
      "status": 2 
     } 
     } 
    } 
    ], 
    "configuration_version": "1" 
} 

Oright,現在火力地堡控制檯。

  • 套件名稱創建項目
  • 從JKS產生加SHA1指紋文件
  • 啓用谷歌認證的登入

就是這樣我想,希望我提供的一切,
所以我在這裏想念什麼。

當我點擊谷歌標誌,它給我一個錯誤狀態碼。我不知道這裏有什麼問題。任何人?

在此先感謝。

+0

你有沒有建立一個調試APK,並試圖登錄呢? –

+0

明顯,但不同的sha1指紋 – Reoxey

+0

這是否失敗,具有相同的地位? –

回答

0

如果要添加的所有SHA-1指印的火力點還是你得到error.then(我面臨這個問題後,這個步驟它的解決。)試試這個步驟:

1.Go到Google控制檯API憑證頁面。

2.Click在左側選項卡中的憑據。

3.Already兩個默認的Android和Web OAuth用戶端ID將存在。您必須創建一個Android客戶端和一個Web 2.0客戶端。

4.Go到Firebase.In項目設置,下載谷歌-services.json和應用程序文件夾中粘貼。

(一切都很好,但你仍然是不能簽到谷歌表示可能OAuth的問題。所以一定要在憑證頁面ID.Finally創建Android和Web客戶端,你有2個Android客戶端和兩個Web客戶端編號。)

填寫OAuth的內容屏幕也

1

當你建立你的GoogleSignInOptions,你使用字符串資源web_client_key。出於安全原因,您沒有發佈真正的密鑰,而是使用示例值123456789-clientwebapplication.apps.googleusercontent.com.

該示例值沒有出現在發佈的google-services.json中,所以我無法將其與那裏的值進行匹配。值應該是在該塊中定義的client_id

{ 
    "client_id": "{numeric-id}-webapplication.apps.googleusercontent.com", 
    "client_type": 3 
} 

這是您使用的值嗎?

獲取web客戶端ID的conventional way是使用字符串資源R.string.default_web_client_id,這是由從Google Services Gradle Plugin產生google-services.json。是否有一個原因,你不能這樣做,必須定義你自己的字符串資源?你有沒有試過用default_web_client_id

+0

是的,字符串中的'client_id'與google-services.json匹配,我很清楚'default_web_client_id'。也試過了。它不起作用。 – Reoxey

+1

我的問題與上面相同,但不是配置問題。這似乎是ISP提供商的問題。我嘗試過不同的ISP提供商,它似乎工作。 – coder