Authenticate Using Google Sign-In on Android 遇上status code: 12501
近日有Android Project用到Firebase的authentication,粗心大意的我花了數小時去解決一個簡單問題。
事源我正在依照Google Firebase 的指引,一步一步去實作"Authenticate Using Google Sign-In on Android",本認為一切都清楚理解並小心Copy and Paste,但當我把手機以Debug mode直接安裝測試時卻看到登入失敗的字樣。
收到的GoogleSignInResult getStatus() 會列印出:
Status{statusCode=unknown status code: 12501, resolution=null}
(有關code 12501可參考: https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInStatusCodes)
![]() |
出現失敗的位置是這個GoogleSignInResult result |
我重頭來回幾次較對程式碼肯定沒有Typo ,還打開了以前使用了Google Authentication的project source code sample來比較,找到一個比較大的分別就是多了以下此句:
.requestIdToken(getString(R.string.default_web_client_id))
![]() |
這是建立GoogleSignInOptions object 的一段 |
細心組織一下思維後,發現自己忘記把Debug build 的Keystore SHA1憑證指紋加到專案,所以沒有權限去requestIdToken() 。
因為Debug build 和Release build 所使用的Keystore是不同的,所以要另行加入。