Android Drive GooglePlayServicesUtil:指定账号无法登录

标签 android google-drive-api google-drive-android-api

我需要使用 Drive API 创建一个文件,其中包含我的应用程序中的一些内容,因此我遵循了 Drive API 网页上的“入门”部分。

所以我在我的开发者控制台上启用了 api,创建了一个 OAuth 客户端 ID,正如它所说的那样。 (如果我还没有支付 2 美元,我可以使用 api 吗?)

关于我正在执行的 onCreate 方法的设置 Activity :

 googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Drive.API)
            .addScope(Drive.SCOPE_FILE)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

我正在实现这些方法:

@Override
protected void onStop(){
    getGoogleApiClient().disconnect();
    super.onStop();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putBoolean(STATE_RESOLVING_ERROR, resolvingError);
}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    if (resolvingError) {
        // Already attempting to resolve an error.
        return;
    }else if (connectionResult.hasResolution()) {
        try {
            resolvingError = true;
            connectionResult.startResolutionForResult(this,RESOLVE_CONNECTION_REQUEST_CODE);
        } catch (IntentSender.SendIntentException e) {
            getGoogleApiClient().connect();
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
        resolvingError = true;
    }
}

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if(requestCode == RESOLVE_CONNECTION_REQUEST_CODE) {
        resolvingError = false;
        if (resultCode == RESULT_OK) {
            if(!getGoogleApiClient().isConnecting() && !getGoogleApiClient().isConnected()){
                getGoogleApiClient().connect();
            }
        }
    }
}

@Override
public void onConnected(Bundle bundle) {
    Toast.makeText(this, "Success!!! :D :D", Toast.LENGTH_SHORT).show();
}

@Override
public void onConnectionSuspended(int i) {}

然后我在按钮的 onclick 方法上调用 googleApiClient.connect();

我收到选择帐户 google drive 对话框,选择一个帐户并按 OK,我在连接结果中收到此错误:

E/GooglePlayServicesUtil﹕ The specified account could not be signed in.

我在网上搜索并找不到这个问题的原因......也许我在开发者控制台上做错了......不知道......

更新:

所以我删除了 Google 开发者控制台上的项目并重新创建它,我还添加了 Drive Api 并启用它,我在授权屏幕上添加了一个产品名称,以及一个包含我的包名称和 sha1 id 的新客户端 ID ...

同时更新我的​​ list ,

添加到 list 标签:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />   
<uses-permission android:name="android.permission.USE_CREDENTIALS" />

应用标签:

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

到我进行连接的 Activity 标签:

<meta-data
       android:name="com.google.android.apps.drive.APP_ID"
       android:value="id=<app id i took this id from developers´console>" />
<action android:name="com.google.android.apps.drive.DRIVE_OPEN" />
<data android:mimeType="application/vnd.google-apps.drive-sdk.<app id>" />

我还使用调试 keystore 构建了一个签名的 apk 来测试我的应用程序。 (在真实设备上)。

毕竟错误仍在上升......

最佳答案

My guess is that there is a problem with the setup you did at the Developer's Console. This discussion may be helpful. – qbix

你好,阅读上面提到的 qbix 讨论,我刚刚找到了问题的原因......

我的项目结构中的默认风格有一个不正确的应用程序 ID,我只是将它更改为我的应用程序包“com.xxxxx.yyyyy”。

所以我相信当 googleApiClient 尝试连接时,在 id 客户端凭证中找到不同的包名称并拒绝访问....

现在工作正常 thanx....

关于Android Drive GooglePlayServicesUtil:指定账号无法登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31252524/

相关文章:

android - 仅将外部库的 “minifyEnabled”设置为 “false”

android - 生成已签名的 apk 任务应用程序时出错 :packageRelease

javascript - 无法使用 Google App Script 上传到 Google Drive 上的子文件夹

oauth-2.0 - Google Marketplace - 安装应用程序和访问 token

android - Google 云端硬盘 API 不可用

android - 获取 Android 应用程序中的文件夹,该文件夹不是通过此应用程序创建的

清除错误后,Android TextInputLayout 保持红色

google-apps-script - DriveApp 从 DocX 到 PDF 的转换失败

android - 查询失败 Google Drive Android

Android 应用程序使用来自 Web 服务的数据