gpt4 book ai didi

Google Drive Api 的 Android 访问 token 下载文件

转载 作者:行者123 更新时间:2023-11-30 00:22:14 24 4
gpt4 key购买 nike

根据 this 从 google drive 下载文件我们必须使用

获取 https://www.googleapis.com/drive/v3/files/0B9jNhSvVjoIVM3dKcGRKRmVIOVU?alt=media授权:不记名'ACCESS_TOKEN'

我想知道这个访问 token 到底是什么?这是android客户端ID吗?在 Authorization header 中传递客户端 ID 时,它会给出 401 未授权错误。如果我使用下面给定的代码,文件下载成功但是当我尝试打开它时,它说文件无效

OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().get(fileId)
.executeMediaAndDownloadTo(outputStream);

最佳答案

您可以添加 Drive API Client Library for Java进入模块的 build.gradle... 而不是为谷歌云端硬盘 REST API。 clientId 应该来自 google-services.json 文件(并且可能与 REST 凭据不同,请检查控制台)。

依赖关系{

// Google HTTP Client :

compile 'com.google.http-client:google-http-client-android:1.22.0'
compile 'com.google.http-client:google-http-client-jackson2:1.22.0'

// Google API Client :

compile 'com.google.api-client:google-api-client-android:1.22.0'
compile 'com.google.api-client:google-api-client-jackson2:1.22.0'

// Google OAuth Client :

compile 'com.google.oauth-client:google-oauth-client:1.22.0'

// Google Drive API :

compile 'com.google.apis:google-api-services-drive:v3-rev65-1.22.0'

}

然后运行 ​​./gradlew clean 来下载库。

关于Google Drive Api 的 Android 访问 token 下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46056190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com