Google Drive Auth始终返回0

BMK*_*BMK 5 google-drive-api google-play-services google-drive-android-api

我正在使用此https://developers.google.com/drive/android/auth#connecting_and_authorizing_the_google_drive_android_api中显示的代码

在我的应用程序中,我单击以连接到驱动器,但它导致此行正在执行

 connectionResult.startResolutionForResult(this, 1);
Run Code Online (Sandbox Code Playgroud)

由于连接失败.

然后它会打开一个帐户菜单供我选择帐户.当我点击它然后对话框解除,我仍然无法连接到谷歌驱动器,因为每次结果代码为0

protected void onActivityResult(final int requestCode, final int resultCode,      final Intent data) {
    switch (requestCode) {
        case 1:
            if (resultCode == RESULT_OK) {
                mGoogleApiClient.connect();
           }
            break;
    }
}
Run Code Online (Sandbox Code Playgroud)

我会假设代码是正确的,但有人知道我需要做什么来防止取消?我相信我为OA Auth正确设置了我的凭据

Rey*_*cia 0

我在这里尝试使用 Google 的 Drive 演示代码,并且能够运行 Android 示例。检查他们的身份验证实现并尝试将其与您的进行比较。这是相关部分:

@Override
    protected void onResume() {
        super.onResume();
        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(Drive.API)
                    .addScope(Drive.SCOPE_FILE)
                    .addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();
        }
        mGoogleApiClient.connect();
    }

    /**
     * Handles resolution callbacks.
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_RESOLUTION && resultCode == RESULT_OK) {
            mGoogleApiClient.connect();
        }
    }
Run Code Online (Sandbox Code Playgroud)

我能够成功登录并尝试了一些功能。如果您要使用此示例,请不要忘记设置您的凭据(例如 Oauth CliendID)并指明入门指南中指示的正确包名称。

它看起来是这样的:

在此输入图像描述