【发布时间】:2017-11-08 09:26:43
【问题描述】:
尽管从官方示例应用中复制了代码,但在通过 Play 商店发布应用时未显示身份验证同意屏幕。我已经在 Google Api Developer Console 上正确生成了两个 OAuth 2.0 凭据,一个用于发布(使用我的私有密钥库),一个用于调试(使用 Android Studio 调试密钥库)。
更新:在调试模式下在较旧的 4.4 模拟器上安装我的应用程序我注意到在较新的设备上发布应用程序的行为相同。没有出现同意屏幕,Logcat 显示此消息:
W/GooglePlayServicesUtil:Google Play 服务已过期。需要 11717000 但找到了 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();
}
【问题讨论】:
标签: android google-drive-api google-play-services google-oauth google-drive-android-api