播放服务11.6:OAuth同意屏幕在发布时未显示

时间:2017-11-08 09:26:44

标签: android google-drive-api google-play-services google-oauth google-drive-android-api

尽管从官方示例应用程序复制了代码,但是当通过Play商店发布应用程序时,未显示身份验证同意屏幕。我已在Google Api开发者控制台上正确生成了两个OAuth 2.0凭据,一个用于发布(使用我的私钥库),另一个用于调试(使用Android Studio调试密钥库)。

更新:在调试模式下在旧的4.4模拟器上安装我的应用程序我注意到在新设备上发布应用程序的相同行为。没有同意屏幕,Logcat显示以下消息:

  

W / GooglePlayServicesUtil:Google Play服务已过期。需要   11717000但发现11509030

可能是因为较新的GoogleApi接口无法提示用户安装/更新PlayServices,即使官方文档说明了这一点吗?

这是我的代码:

build.gradle(app)

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();
    }

2 个答案:

答案 0 :(得分:1)

我回答我自己的问题。问题是Google Play服务没有更新,最近的GoogleApi界面没有检查(可能是一个错误?)。 因此,您必须在尝试身份验证之前进行检查:

const takeOrder = (size, beverage, milk, flavouring) => {
    console.log("Order: A " + size + " " + beverage + " made of " + milk + " with added " + flavouring);
    total += data[beverage][size] + (data[milk] || 0) + (data[flavouring] || 0);
    //                                          ^^^^ use a default value if the key does
    //                                               not exist in the object or is falsy
    orderCount++;
};

var data = {
        latte: {
            large: 1000
        },
        cappuchino: {
            medium: 1000
        },
        'latte macchiato': {
            small: 1000
        },
        'coconut milk': 160
    },
    orderCount = 0,
    total = 0;

takeOrder('large', 'latte', 'soy milk', 'caramel syrup');
takeOrder('medium', 'cappuchino', 'coconut milk', 'vanilla syrup');
takeOrder('small', 'latte macchiato', 'lactose free milk', 'sugar-free hazelnut syrup');

console.log(orderCount);
console.log(total);

希望它可以帮助别人!

答案 1 :(得分:0)

对于其他人,GoogleSignIn.getClient(此/ * activity * /,signInOptions)通常应根据需要自动提示Play服务更新。

但在最新的11.6 SDK中,此功能暂时被targetSdkVersion 26破坏。请考虑在这些条件下使用GoogleApiAvailability.showErrorDialogFragment(),直到在将来的版本中修复它。