android - 哪些是在我的 Android 应用程序中从 Google Drive 下载 google 表格所需的服务器端权限集
问题描述
我的具体问题是
当我打电话时
driveService.files().export(fileId, "text/csv").executeMediaAndDownloadTo(outputStream);
从我的应用程序我得到
11-22 00:35:02.489 : com.google.api.client.http.HttpResponseException: 401 Unauthorized
11-22 00:35:02.490 : {
11-22 00:35:02.491 : "error": {
11-22 00:35:02.491 : "errors": [
11-22 00:35:02.491 : {
11-22 00:35:02.491 : "domain": "global",
11-22 00:35:02.491 : "reason": "authError",
11-22 00:35:02.491 : "message": "Invalid Credentials",
11-22 00:35:02.492 : "locationType": "header",
11-22 00:35:02.492 : "location": "Authorization"
11-22 00:35:02.492 : }
11-22 00:35:02.492 : ],
11-22 00:35:02.492 : "code": 401,
11-22 00:35:02.492 : "message": "Invalid Credentials"
11-22 00:35:02.493 : }
11-22 00:35:02.493 : }
当我在 Services / Drive API v3 / drive.files.export 上使用 APIs Explorer 时,我得到了我想要的数据。
我的问题是:
我该如何解决这个问题。
当我登录时获得了一个谷歌帐户......这不足以知道我输入的用户/密码以及在智能手机中注册的用户/密码......我是对的吗?
哪些是我需要在服务器端设置的最小权限集才能获得权限
如何检查哪些是不允许从谷歌驱动器下载谷歌表的特定权限问题?
非常感谢您的任何回复。
我与此问题相关的 Java 代码片段(登录过程)
在服务器端
我的应用程序凭据是:
- 网络客户端
- 安卓客户端
我使用“Web 客户端”的客户端 ID 如果我使用 Android 客户端的 clientId,我不会得到 idToken
启用库 API:
- Google Drive API 使用 Oauth 2.0 授权请求 - 在 drive.files.export
- 谷歌表格 API
在安卓应用中
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(this.googleClientId)
.requestEmail()
.build();
...
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
...
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
...
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
validateGoogleUser(data);
}
}
...
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(this.dataIntent);
...
GoogleSignInAccount account = task.getResult(ApiException.class);
...
// It returns my account with id / idToken / mail / names / ... more
And then... I continue
在我尝试下载的方法中,这是代码
//TODO: move this to a service and to a dao
final HttpTransport HTTP_TRANSPORT = AndroidHttp.newCompatibleTransport();;
GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
Drive driveService = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(applicationName)
.build();
String fileId = idSheet;
//TODO: Check how to check progress and limit size of download or cancel the operation after n seconds
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().export(fileId, "text/csv")
.executeMediaAndDownloadTo(outputStream);
注意:我不使用 - GoogleIdTokenVerifier.verify
我也不知道它是什么......因为我已经得到了我的帐户信息。
解决方案
我找到了问题的解决方案。服务器端的权限没问题。但在这个项目中,我分叉的是谷歌登录和谷歌驱动器连接的组合,我需要从我的 Android 应用程序下载或使用谷歌驱动器文件
推荐阅读
- ceylon - 新锡兰项目具有无法打开的“module.ceylon”
- java - Spring和hibernate数据库结果spring比较有效,但仍然抛出错误
- javascript - 如何使 will_paginate 的无限滚动与 Rails 5 中的无刷新搜索一起工作?
- php - PHP显式调用python版本
- python - 在 Python 中创建具有多个操作的函数
- python - 逐行逐字检查文本文件python
- postgresql - PostgreSQL与时间列的时间差(以分钟为单位)?
- c++ - 在 C++ 中将定义的结构转换为双精度(复数)
- reactjs - 试图在图像中渲染 pdf 但链接路径错误
- c# - Android Web 服务器请求