[英]Can't get token id from google in android google log in
我已經在Google控制台上將我的Android應用程序簽名為api,並且在Google控制台中將后端服務器作為oauth客戶端簽名了。
我還更新了gradle文件,並更新了獲得令牌ID的必要條件。
但是無論如何,我總是無法從Google獲得令牌。
我已經從Google控制台檢查了程序包名稱和ssh1代碼,並通過以下命令將其與我的調試ssh1匹配: keytool -list -v -keystore mydebudpath\\debug.keystore
我將在這里提交我的android代碼:
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
validateServerClientID();
// [START configure_signin]
// Request only the user's ID token, which can be used to identify the
// user securely to your backend. This will contain the user's basic
// profile (name, profile picture URL, etc) so you should not need to
// make an additional call to personalize your application.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.server_client_id))
.requestServerAuthCode(getString(R.string.server_client_id), false)
.requestEmail()
.build();
// [END configure_signin]
// Build GoogleAPIClient with the Google Sign-In API and the above options.
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.enableAutoManage(getActivity()/* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}
和我的onActivityResult:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_GET_TOKEN) {
// [START get_id_token]
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
Log.d(TAG, "onActivityResult:GET_TOKEN:success:" + result.getStatus().isSuccess());
if (result.isSuccess()) {
GoogleSignInAccount acct = result.getSignInAccount();
String idToken = acct.getIdToken();
// Show signed-in UI.
Log.d(TAG, "idToken:" + idToken);
updateUI(true);
// TODO(user): send token to server and validate server-side
} else {
// Show signed-out UI.
updateUI(false);
}
// [END get_id_token]
}
}
代碼result.getStatus().isSuccess();
總是返回false
另請注意,在上面的代碼中,我的R.string.server_client_id
是我的服務器的client_id,它是我在Google Developer Console中作為網絡應用程序oauth2創建的。
我從未在我的android身份驗證代碼中使用過我的android api_key
。 我應該在哪里使用它?
我做錯了哪一部分?
這是我的清單,可能對您有用
如果所有其他方法均失敗,建議您嘗試基於Google Developer Console中的新項目創建一個新的api密鑰,祝您好運!
有用的信息:developers.google.com/identity/sign-in/android/start-integrating
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.