Android API Google Drive"连接失败"

cha*_*ham 6 android google-drive-api

我尝试在Android上使用API​​ Google Drive,首先使用该演示:

https://github.com/googledrive/android-quickstart

但是,我有这个错误,我无法解决.

GoogleApiClient连接失败:ConnectionResult {statusCode = SIGN_IN_REQUIRED,resolution = PendingIntent {421d40e8:android.os.BinderProxy@42137f78}}

@Override
public void onConnectionFailed(ConnectionResult result) {
    // Called whenever the API client fails to connect.
    Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
    if (!result.hasResolution()) {
        // show the localized error dialog.
        GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 0).show();
        return;
    }
    // The failure has a resolution. Resolve it.
    // Called typically when the app is not yet authorized, and an
    // authorization
    // dialog is displayed to the user.
    try {
        result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
    } catch (SendIntentException e) {
        Log.e(TAG, "Exception while starting resolution activity", e);
        // There was an error with the resolution intent. Try again.
        mGoogleApiClient.connect();
    }
}


@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (requestCode == REQUEST_CODE_RESOLUTION) {

        if (resultCode == RESULT_OK) {
            Log.i(TAG, "Error resolution success.");

            // Make sure the app is not already connected or attempting to connect
            if (!mGoogleApiClient.isConnecting() &&
                    !mGoogleApiClient.isConnected()) {
                mGoogleApiClient.connect();
            }

        } else {
            GooglePlayServicesUtil.getErrorDialog(requestCode, this, 0).show();
        }

        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

And*_*ndy 2

是您收到的错误的信息。我假设您是,但您需要登录才能访问云端硬盘。当我运行示例应用程序时,它一开始就要求我选择一个帐户。也许您没有与您正在使用的设备同步的帐户?有一个“添加帐户”选项,但当您有零个帐户时,行为可能会有所不同。该文档建议您要么继续而不使用 API(只是因为除非您登录,否则您不能这样做),或者调用提示startResolutionForResult(Activity, int)用户登录,但最简单的方法可能是将帐户添加到您的设备