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

六眼飞鱼酱① 提交于 2019-12-20 10:52:07

问题


Here is the story. I had integrated Google Drive Android SDK (8.1.0) into my app (AnyCopy) around three years ago. And I followed the tutorial to set up properly including adding credentials and api key. 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.

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

java.util.concurrent.ExecutionException: com.google.android.gms.common.api.ApiException: 17: API: Drive.API_CONNECTIONLESS is not available on this device. at com.google.android.gms.tasks.Tasks.zzc(Unknown Source) at com.google.android.gms.tasks.Tasks.await(Unknown Source)

However, if I create a new credential on Google Console with a different signing key. 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. Anyone else has ever run into this issue? Any suggestion will he highly appreciated.


回答1:


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. Going to the dashboard and enabling the google drive API did the trick. Hope that helps.




回答2:


The new API you are using still got the instances and the folders of the older version. You just can check by switching from Android to your project and external libraries. If there is the presence of the older version of that api, try refractor and clean the project and Rebuild it. Hope it suits your concern. Surely a backward compatibility issue.




回答3:


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:

Note: The Google Drive Android API currently only supports drive.file and drive.appfolder authorization scopes. If your application requires additional permissions or features not yet available in the Drive Android API, you must use the Google APIs Java Client.

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.

To solve that I just removed all other scopes and left only the drives.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.

If you're using firebase your code will look a bit like that:

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

But if you're using only straight the GoogleSignInClient it would look like that:

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.

I really hope that helps you, I've lost some hours until notice that, unfortunately.

Thanks,



来源:https://stackoverflow.com/questions/49568796/com-google-android-gms-common-api-apiexception-17-api-drive-api-connectionles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!