android - Google Drive : sign in failed. 登录指定帐户时出错

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

我试图让我的用户选择要上传到我的服务器以进行更多处理的文件。我无法让登录正常工作,也无法弄清楚原因。下面是我用来启动与 Google 的握手的代码:

public GoogleApiClient getGoogleApiClient() {
    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .addScope(Drive.SCOPE_APPFOLDER)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }
    return mGoogleApiClient;
}

private void getDataFromGoogleDrive() {
    try {
        IntentSender intentSender = Drive.DriveApi.newOpenFileActivityBuilder().build(getGoogleApiClient());
        getActivity().startIntentSenderForResult(intentSender, RC_SIGN_IN, null, 0, 0, 0);
    } catch (IntentSender.SendIntentException e) {
        Log.w(TAG, "Unable to send intent", e);
        getGoogleApiClient().connect();
    }
}

public void onConnected(Bundle bundle) {
    if (getGoogleApiClient().isConnected()) {
        getDataFromGoogleDrive();
    }
}

public void onConnectionSuspended(int i) {
}

public void onConnectionFailed(ConnectionResult connectionResult) {
    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(getActivity(), RC_SIGN_IN);
        } catch (IntentSender.SendIntentException e) {
            // Unable to resolve, message user appropriately
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), getActivity(), 0).show();
    }
}


protected void onActivityResult(int requestCode, int resultCode, Intent data){
    if (requestCode == RC_SIGN_IN) {
        if (!getGoogleApiClient().isConnecting()) {
            getGoogleApiClient().connect();
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

我也遵循了这里的指示:

https://developers.google.com/drive/android/auth#connecting_and_authorizing_the_google_drive_android_api

我在这里遗漏了什么吗?我的凭据是准确的,因为我也在 Google map 上使用了相同的凭据。在我的 list 中,我有以下内容:

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

我注意到 Google 云端硬盘不需要我传递 API key ?那是对的吗?除此之外,我想不出任何东西——但文档并没有说它是必需的。

我的 build.grade 文件依赖在这里:

compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.android.support:support-annotations:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:design:23.0.0'

最佳答案

我遇到了同样的事情。看起来您还需要设置 OAuth 2.0 凭证。一旦我这样做了,它就奏效了。

关于android - Google Drive : sign in failed. 登录指定帐户时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32242218/

相关文章:

android - 在 Recyclerview 的适配器中使用 DataBinding 库的点击事件

没有动画的Android ViewFlipper翻转

node.js - 通过 nextPageToken 在 Google Drive API 中检索下一页的正确语法是什么

java - 在 Web 应用程序上下文中从 Uri 转换为文件路径

android - Facebook 集成在模拟器中工作但不在 android 设备中工作?

jquery - 未存储 Android JQuery 移动 cookie

android - Admob 中的更新 - 缺失

android - getToken() 失败。状态 BAD_AUTHENTICATION 错误

ios - 适用于 iOS 的 Google 云端硬盘实时 API

java - AdMob 横幅不适用于移动数据