Google 已弃用 Google Drive Android API。
我们正在迁移到 Google Drive REST API (v3)。
2 年前,我们有使用 Google Drive REST API (v2) 的经验。我们知道 GET_ACCOUNTS
权限是必需的,GoogleAuthUtil.getToken()
才能正常工作 - Google Drive API - the name must not be empty: null (But I had passed valid account name to GoogleAccountCredential)
当我们查看 Google Drive REST API (v3) 示例时 - https://github.com/gsuitedevs/android-samples/blob/master/drive/deprecation/app/src/main/AndroidManifest.xml#L5 ,我们注意到 Google 团队确实明确提到了
<!-- Permissions required by GoogleAuthUtil -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
令人惊讶的是,当我们运行示例应用程序 (https://github.com/gsuitedevs/android-samples/tree/master/drive/deprecation) 时,没有针对 Android 6 和 8 弹出运行时权限对话框。然而,该应用程序可以正常运行。
我们预计该应用程序将无法运行,因为没有为该应用程序授予 GET_ACCOUNTS
权限。但是,它仍然可以毫无问题地与 Google Drive 服务进行授权和通信。
这是我目前测试过的内容
我已经在 Android 5、Android 6 和 Android 8 中进行了测试。没有为 Android 6 和 Android 8 授予运行时 GET_ACCOUNTS
权限。
我还在进一步测试,通过从 list 中完全删除 GET_ACCOUNTS
和 MANAGE_ACCOUNTS
。不过,Android 5、Android 6 和 Android 8 都可以使用。在运行之前,我已经清除了应用程序的缓存和存储空间。
那么,Google Drive REST API 是否仍然需要 GET_ACCOUNTS
运行时权限请求才能工作?
最佳答案
根据 Authorizing and Using REST APIs , 它似乎不是必需的 - 因为 GoogleSignInApi可以使用,它请求 oAuth2
访问范围并且不需要直接访问设备上的功能。它从 Play Services 获取用户帐户,Play Services 知道登录的帐户并充当委托(delegate)。
刚刚试过,唯一的区别是必须添加 access-scopes作为字符串:
GoogleSignInOptions gso = new GoogleSignInOptions
.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope("https://www.googleapis.com/auth/drive.readonly"))
.requestEmail()
.build();
this.mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
...
关于android - Google Drive REST API 是否仍需要 GET_ACCOUNTS 权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53941095/