gpt4 book ai didi

android - 播放服务 11.6 : OAuth consent screen not showing when published

转载 作者:行者123 更新时间:2023-11-29 01:06:00 24 4
gpt4 key购买 nike

尽管已从官方示例应用程序复制代码,但当应用程序通过 Play 商店发布时,身份验证同意屏幕不会显示。我已经在 Google Api Developer Console 上正确生成了两个 OAuth 2.0 凭据,一个用于发布(使用我的私有(private) keystore ),一个用于调试(使用 Android Studio 调试 keystore )。

更新:在 Debug模式下将我的应用程序安装在较旧的 4.4 模拟器上,我注意到发布应用程序在较新设备上的行为相同。未出现同意屏幕,Logcat 显示此消息:

W/GooglePlayServicesUtil: Google Play services out of date. Requires 11717000 but found 11509030

会不会是更新的GoogleApi界面无法提示用户安装/更新 PlayServices,即使官方文档这么说?

这是我的代码:

build.gradle(应用程序)

compile 'com.google.android.gms:play-services-auth:11.6.0'
compile 'com.google.android.gms:play-services-drive:11.6.0'

AndroidManifest.xml

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

DriveActivity.java

private static final int REQUEST_CODE_SIGN_IN = 0;

protected GoogleSignInClient mGoogleSignInClient;
protected DriveClient mDriveClient;
protected DriveResourceClient mDriveResourceClient;

protected abstract void onDriveConnected();

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_SIGN_IN:
if (resultCode == RESULT_OK) {
Task<GoogleSignInAccount> getAccountTask = GoogleSignIn.getSignedInAccountFromIntent(data);
if (getAccountTask.isSuccessful()) {
initializeDriveClient(getAccountTask.getResult());
}
else {
Toast.makeText(this, "Sign-in failed.", Toast.LENGTH_LONG).show();
}
}
break;
}
}

protected void signIn() {
GoogleSignInAccount signInAccount = GoogleSignIn.getLastSignedInAccount(this);
if (signInAccount != null && signInAccount.getGrantedScopes().contains(Drive.SCOPE_FILE)) {
initializeDriveClient(signInAccount);
}
else {
GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Drive.SCOPE_FILE)
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, signInOptions);
startActivityForResult(mGoogleSignInClient.getSignInIntent(), REQUEST_CODE_SIGN_IN);
}
}

private void initializeDriveClient(GoogleSignInAccount signInAccount) {
mDriveClient = Drive.getDriveClient(this, signInAccount);
mDriveResourceClient = Drive.getDriveResourceClient(this, signInAccount);
onDriveConnected();
}

最佳答案

我回答我自己的问题。问题是 Google Play 服务没有更新,最近的 GoogleApi 接口(interface)没有检查它(可能是一个错误?)。所以你必须在尝试身份验证之前进行检查:

protected void signIn() {
if (checkPlayServices()) {
...
}
}

private boolean checkPlayServices() {
GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
int result = googleAPI.isGooglePlayServicesAvailable(this);
if (result != ConnectionResult.SUCCESS) {
if (googleAPI.isUserResolvableError(result)) {
googleAPI.getErrorDialog(this, result, PLAY_SERVICES_RESOLUTION_REQUEST).show();
}
else {
Toast.makeText(this, R.string.message_unsupported_device, Toast.LENGTH_LONG).show();
}
return false;
}
return true;
}

希望对其他人有帮助!

关于android - 播放服务 11.6 : OAuth consent screen not showing when published,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47175923/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com