Meh*_*kri 3 authentication android google-plus google-oauth developer-console
我已将我的 Android 应用程序签名为 google console 上的 api,并将我的后端服务器签名为 google console 中的 oauth 客户端。
我还更新了我的 gradle 文件,以及获取令牌 Id 所需的一切。
但不知何故,我总是无法从谷歌获得令牌。
我已经从 google 控制台检查了我的包名称和 ssh1 代码,并通过 with 命令将其与我的调试 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();
}
Run Code Online (Sandbox Code Playgroud)
和我的 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]
}
}
Run Code Online (Sandbox Code Playgroud)
代码result.getStatus().isSuccess();总是返回false
请注意,在上面的代码中,我R.string.server_client_id是我的服务器的 client_id,我在 google 开发者控制台中将其创建为 Web 应用程序 oauth2。
我从未api_key在我的 Android 身份验证代码中使用过我的 Android。我应该在哪里使用它?
我哪一部分做错了?
小智 6
这是我的清单,可能对您有用
如果一切都失败了,我建议您尝试根据 Google 开发者控制台中的新项目创建一个新的 api 密钥,祝您好运!
有用信息:developers.google.com/identity/sign-in/android/start-integrating
| 归档时间: |
|
| 查看次数: |
8104 次 |
| 最近记录: |