简体   繁体   English

com.google.android.gms.common.api.ApiException: 17: API: Drive.API_CONNECTIONLESS 在此设备上不可用

[英]com.google.android.gms.common.api.ApiException: 17: API: Drive.API_CONNECTIONLESS is not available on this device

Here is the story.这是故事。 I had integrated Google Drive Android SDK (8.1.0) into my app ( AnyCopy ) around three years ago.大约三年前,我将 Google Drive Android SDK ( 8.1.0 ) 集成到我的应用程序 ( AnyCopy ) 中。 And I followed the tutorial to set up properly including adding credentials and api key.我按照教程进行了正确设置,包括添加凭据和 api 密钥。 Everything worked okay.一切正常。 I could backup and restore my data without any problem.我可以毫无问题地备份和恢复我的数据。 Even today it works okay if I download it from Google Play.即使在今天,如果我从 Google Play 下载它也可以正常工作。

Recently I have been trying to refactor AnyCopy and integrate the newest Google Drive Android SDK (Google Play Service Version number 12.0.1 )into my app and experiencing a strange error with message最近我一直在尝试重构 AnyCopy 并将最新的 Google Drive Android SDK(Google Play 服务版本号 12.0.1)集成到我的应用程序中,但遇到了一个奇怪的错误消息

java.util.concurrent.ExecutionException: com.google.android.gms.common.api.ApiException: 17: API: Drive.API_CONNECTIONLESS is not available on this device. java.util.concurrent.ExecutionException: com.google.android.gms.common.api.ApiException: 17: API: Drive.API_CONNECTIONLESS 在此设备上不可用。 at com.google.android.gms.tasks.Tasks.zzc(Unknown Source) at com.google.android.gms.tasks.Tasks.await(Unknown Source)在 com.google.android.gms.tasks.Tasks.zzc(来源不明) 在 com.google.android.gms.tasks.Tasks.await(来源不明)

However, if I create a new credential on Google Console with a different signing key.但是,如果我使用不同的签名密钥在 Google 控制台上创建新凭据。 And the problem is resolved.问题解决了。 I realize that the problem rooted from the credential configuration.我意识到问题源于凭证配置。 However, I could not figure out how to resolve it as it might be a Google Drive SDK backwards compatibility bug.但是,我无法弄清楚如何解决它,因为它可能是 Google Drive SDK 向后兼容性错误。 Anyone else has ever run into this issue?还有其他人遇到过这个问题吗? Any suggestion will he highly appreciated.任何建议他都会高度赞赏。

I had the same error.我有同样的错误。 I created a new project and got the credentials for the google API but forgot to enable the Google Drive API.我创建了一个新项目并获得了 google API 的凭据,但忘记启用 Google Drive API。 Going to the dashboard and enabling the google drive API did the trick.转到仪表板并启用 google drive API 就可以了。 Hope that helps.希望有帮助。

The new API you are using still got the instances and the folders of the older version.您使用的新 API 仍然具有旧版本的实例和文件夹。 You just can check by switching from Android to your project and external libraries.您只需从 Android 切换到您的项目和外部库即可进行检查。 If there is the presence of the older version of that api, try refractor and clean the project and Rebuild it.如果存在该 api 的旧版本,请尝试 refractor 并清理项目并重建它。 Hope it suits your concern.希望它适合您的关注。 Surely a backward compatibility issue.当然是向后兼容性问题。

What has happened in my case was that I was setting an authorization scope different from the scopes that the DriveClient object supported that is only drives.file and drive.appfolder as you see here :在我的情况下发生的事情是,我设置的授权范围与DriveClient对象支持的范围不同,只有drive.filedrive.appfolder,如您在此处看到的:

Note: The Google Drive Android API currently only supports drive.file and drive.appfolder authorization scopes.注意:Google Drive Android API 目前仅支持 drive.file 和 drive.appfolder 授权范围。 If your application requires additional permissions or features not yet available in the Drive Android API, you must use the Google APIs Java Client.如果您的应用程序需要 Drive Android API 中尚不可用的其他权限或功能,您必须使用 Google APIs Java 客户端。

In my case, I was trying to use the full drive access and the error wasn't really related to the connection type.就我而言,我试图使用完整的驱动器访问权限,但错误与连接类型并没有真正相关。 I found it by looking at the CommonStatusCodes class .我通过查看CommonStatusCodes 类找到了它。

To solve that I just removed all other scopes and left only the drives.file .为了解决这个问题,我只是删除了所有其他范围,只留下了drive.file You may, or may not :D, need to revoke the access and log out the users from your app and re-login and request access to their google drive again.您可能需要,也可能不需要:D,需要撤销访问权限并从您的应用中注销用户,然后重新登录并再次请求访问他们的谷歌驱动器。

If you're using firebase your code will look a bit like that:如果您使用的是 firebase,您的代码看起来有点像这样:

AuthUI.IdpConfig.GoogleBuilder()
                    .setScopes(Arrays.asList(Scopes.DRIVE_FILE))
                    .build()

But if you're using only straight the GoogleSignInClient it would look like that:但是,如果您只直接使用GoogleSignInClient,它看起来像这样:

GoogleSignInOptions signInOptions =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestScopes(Drive.SCOPE_FILE)
                    .build();
GoogleSignIn.getClient(this, signInOptions)

If you need more than just access to files and appfolder you won't be able to use the DriveClient class and, according to their docs, will need to Connecting and Authorizing with the Google APIs Java Client .如果您需要的不仅仅是访问文件和应用程序文件夹,您将无法使用 DriveClient 类,并且根据他们的文档,将需要Connecting and Authorizing with the Google APIs Java Client

I really hope that helps you, I've lost some hours until notice that, unfortunately.我真的希望对你有所帮助,不幸的是,我已经失去了几个小时才注意到这一点。

Thanks,谢谢,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM