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

喜欢而已 提交于 2019-12-02 23:28:57

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.

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.

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,

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