Google Drive REST API是否仍需要GET_ACCOUNTS权限? [英] Is GET_ACCOUNTS permission still required for Google Drive REST API?

查看:91
本文介绍了Google Drive REST API是否仍需要GET_ACCOUNTS权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google已弃用Google Drive Android API.

Google has deprecated Google Drive Android API.

我们正在迁移到Google Drive REST API(v3).

We are migrating over to Google Drive REST API (v3).

2年前,我们拥有使用Google Drive REST API(v2)的经验.我们知道需要GET_ACCOUNTS权限才能使GoogleAuthUtil.getToken()正常工作-

2 years ago, we have experience in using Google Drive REST API (v2). We know that GET_ACCOUNTS permission is required, for GoogleAuthUtil.getToken() to work correctly - Google Drive API - the name must not be empty: null (But I had passed valid account name to GoogleAccountCredential)

当我们看一下Google Drive REST API(v3)的示例时-

When we look at example of Google Drive REST API (v3) - https://github.com/gsuitedevs/android-samples/blob/master/drive/deprecation/app/src/main/AndroidManifest.xml#L5 , we notice that Google team does mention explicitly

<!-- 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弹出运行时权限对话框.但是,该应用程序可以正常运行.

Surprisingly, when we run the example app (https://github.com/gsuitedevs/android-samples/tree/master/drive/deprecation), there's no run-time permission dialog being pop up for Android 6 and 8. Yet, the app can work without issue.

我们预计该应用程序将无法运行,因为未为该应用程序授予任何GET_ACCOUNTS权限.但是,它仍然可以进行身份​​验证并与Google云端硬盘服务通信,而不会出现问题.

We expect the app will fail working, as no GET_ACCOUNTS permission was granted for the app. However, it can still auth and communicate with Google Drive service, without issue.

我已经在Android 5,Android 6和Android 8中进行了测试.没有为Android 6和Android 8授予运行时GET_ACCOUNTS权限.

I have tested in Android 5, Android 6 and Android 8. No runtime GET_ACCOUNTS permission is granted for Android 6 and Android 8.

我也通过进一步从清单中删除GET_ACCOUNTSMANAGE_ACCOUNTS进行进一步测试.不过,Android 5,Android 6和Android 8均可以使用.在运行之前,我已经清除了应用程序的缓存并清除了存储.

I'm also further test, by removing GET_ACCOUNTS and MANAGE_ACCOUNTS from Manifest completely. Still, both Android 5, Android 6 and Android 8 are workable. Before running, I have clear cache and clear storage of the app.

那么,是否仍然需要GET_ACCOUNTS运行时权限请求才能使Google Drive REST API正常工作?

So, is GET_ACCOUNTS runtime permission request still required for Google Drive REST API to work?

推荐答案

根据授权和使用REST API 似乎不是必需的-因为 GoogleSignInApi ,它请求oAuth2访问范围,并且不需要直接访问设备上的功能.它从Play服务获取用户帐户,该服务知道已登录的帐户并充当代理.

according to Authorizing and Using REST APIs, it does not seem required - because the GoogleSignInApi can be used, which requests oAuth2 access-scopes and does not require direct access to on-device capabilities. it gets the user account from Play Services, which knows the logged in accounts and acts as the delegate.

只是尝试过,唯一的区别是必须添加访问范围作为字符串:

just tried and the only difference is that one has to add the access-scopes as strings:

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);
...

这篇关于Google Drive REST API是否仍需要GET_ACCOUNTS权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆