Alt=当访问令牌作为查询参数提供时媒体不下载文件
Alt=Media not downloading file when access token is provided as query parameter
您遇到的问题:
使用 get 请求下载文件并通过查询参数授权时出现错误。一旦删除了 alt 查询参数,请求就会按预期执行,并且 returns 文件资源正文。
您期望发生的事情:
在 https://www.googleapis.com/drive/v3/files/[File ID]?supportsAllDrives=true&access_token=[Access Token]&alt=media would download the file properly with no issues, Instead an error is returned Error Screenshot
上执行获取请求
重现步骤:
-> 在 google 驱动器
中创建一个文件
-> 通过授权服务帐户或使用用户帐户获取访问令牌
-> 获取创建的文件的 ID 和使用的帐户的访问令牌,并向 https://www.googleapis.com/drive/v3/files/[File ID]?supportsAllDrives=true&access_token=[Access Token]&alt=media replacing [File ID] 发出请求] 与文件 ID 和 [访问令牌] 与访问令牌
-> 查看结果。预期:文件下载。实际发生了什么:An error is given
其他信息(您尝试过的解决方法、查阅的文档等):
只是为了测试,我尝试删除 alt 参数以查看问题是否仅在尝试下载文件时仍然存在并且确实存在。
我认为您出现问题的原因是 access_token
被用作查询参数。从 2020 年 1 月开始,访问令牌不能与 access_token=###
等查询参数一起使用。 Ref 在这种情况下,请在请求中包含访问令牌 header 而不是查询参数。
例如curl命令示例如下
curl \
-H "Authorization: Bearer [Access Token]" \
'https://www.googleapis.com/drive/v3/files/[File ID]?supportsAllDrives=true&alt=media'
参考文献:
Upcoming changes to the Google Drive API and Google Picker API
First, we’re making changes to authorization for the Google Drive API. If you authorize download requests to the Drive API using the access token in a query parameter, you will need to migrate your requests to authenticate using an HTTP header instead. Starting January 1, 2020, download calls to files.get, revisions.get and files.export endpoints which authenticate using the access token in the query parameter will no longer be supported, which means you’ll need to update your authentication method.
-
您遇到的问题: 使用 get 请求下载文件并通过查询参数授权时出现错误。一旦删除了 alt 查询参数,请求就会按预期执行,并且 returns 文件资源正文。
您期望发生的事情: 在 https://www.googleapis.com/drive/v3/files/[File ID]?supportsAllDrives=true&access_token=[Access Token]&alt=media would download the file properly with no issues, Instead an error is returned Error Screenshot
上执行获取请求重现步骤:
-> 在 google 驱动器
中创建一个文件
-> 通过授权服务帐户或使用用户帐户获取访问令牌
-> 获取创建的文件的 ID 和使用的帐户的访问令牌,并向 https://www.googleapis.com/drive/v3/files/[File ID]?supportsAllDrives=true&access_token=[Access Token]&alt=media replacing [File ID] 发出请求] 与文件 ID 和 [访问令牌] 与访问令牌
-> 查看结果。预期:文件下载。实际发生了什么:An error is given
其他信息(您尝试过的解决方法、查阅的文档等): 只是为了测试,我尝试删除 alt 参数以查看问题是否仅在尝试下载文件时仍然存在并且确实存在。
我认为您出现问题的原因是 access_token
被用作查询参数。从 2020 年 1 月开始,访问令牌不能与 access_token=###
等查询参数一起使用。 Ref 在这种情况下,请在请求中包含访问令牌 header 而不是查询参数。
例如curl命令示例如下
curl \
-H "Authorization: Bearer [Access Token]" \
'https://www.googleapis.com/drive/v3/files/[File ID]?supportsAllDrives=true&alt=media'
参考文献:
Upcoming changes to the Google Drive API and Google Picker API
First, we’re making changes to authorization for the Google Drive API. If you authorize download requests to the Drive API using the access token in a query parameter, you will need to migrate your requests to authenticate using an HTTP header instead. Starting January 1, 2020, download calls to files.get, revisions.get and files.export endpoints which authenticate using the access token in the query parameter will no longer be supported, which means you’ll need to update your authentication method.