Android Drive API startResolutionForResult返回RESULT_CANCELLED

Viz*_*har 6 android drive

我正在尝试将Google云端硬盘应用到我的Android应用中,我甚至无法连接到Api客户端.我不知道为什么:

  1. 我在开发人员控制台中为〜/ .android/debug.keystore配置了项目和凭据(值似乎是正确的)
  2. 我有来自Drive for Android Documentation的复制粘贴代码- >在方法中onConnectionFailed()我正在调用connectionResult.startResolutionForResult()ifconnectionResult.hasResolution()
  3. onActivityResult匹配requestCode我收到resultCode == 0(RESULT_CANCELLED),即使我选择我的帐户

你知道为什么吗?我还尝试添加:

<meta-data
    android:name="com.google.android.apps.drive.APP_ID"
    android:value="----"/>
Run Code Online (Sandbox Code Playgroud)

在文档页面上没有提到但在某些SO帖子上没有提到的Manifest.

感谢帮助

编辑:

我也试过用 enableAutoManage

mGoogleApiClient = new GoogleApiClient.Builder(this)
        .enableAutoManage(this, this)
        .addApi(Drive.API)
        .addScope(Drive.SCOPE_FILE)
        .build();
Run Code Online (Sandbox Code Playgroud)

而不是manualy配置连接和connectionFailed回调:

        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
Run Code Online (Sandbox Code Playgroud)

它在onConnectionFailed方法中返回错误代码13 .基于文档似乎,这在以下情况下返回:

当用户选择不完成提供的解析时,OnConnectionFailedListener传递给enableAutoManage(FragmentActivity,GoogleApiClient.OnConnectionFailedListener).例如,通过取消对话框.

但我没有取消它.

我在Nexus 5x上测试它 - Android N.

Viz*_*har 8

在阅读有关钱包api的内容时,我发现了问题所在

我只需要创建OAuth客户端ID而不是API密钥

  1. 转到开发者控制台>凭据
  2. 点击"创建凭据"> OAuth客户端ID> Android
  3. 填写详细信息
  4. 创建
  5. 打开OAuth许可屏幕(在"凭据"页面上)
  6. 填写电子邮件和产品名称
  7. 保存

现在它有效!