linux - 在对 Google Drive API 的请求正文中写什么?

标签 linux http google-api google-drive-api wget

我正在尝试通过 Linux 控制台使用 GoogleDrive,但我在处理需要正文的请求时遇到了问题。已授予所有权限。所有其他请求(无正文)均有效。

如果我想在 GoogleDrive 中创建文件夹,它会显示错误。

wget --header="Host: www.googleapis.com" --header="Authorization: Bearer MY_TOKEN" --header="Content-Length: 18" --header="Content-Type: application/vnd.google-apps.folder" --method=POST --body-data='{"title":"TemDir"}' 'https://www.googleapis.com/upload/drive/v2/files' -O result.html

响应是:

--2016-07-07 15:03:34--  https://www.googleapis.com/upload/drive/v2/files
Resolving www.googleapis.com (www.googleapis.com)... 209.85.233.95, 2a00:1450:4010:c08::5f
Connecting to www.googleapis.com (www.googleapis.com)|209.85.233.95|:443... connected.
HTTP request sent, awaiting response... 400 Bad Request
2016-07-07 15:03:35 ERROR 400: Bad Request.

当我发送没有正文的请求时,它们都有效:

列出前 3 个文件:

wget --header="Host: www.googleapis.com" --header="Authorization: Bearer MY_TOKEN" --method=GET 'https://www.googleapis.com/drive/v2/files?orderBy=createdDate&maxResults=3' -O result.html

上传视频文件:

wget --header='Host: www.googleapis.com' --header='Content-Type: video/mp4' --header='Content-Length: 9356131' --header='Authorization: Bearer MY_TOKEN' --post-file=test.mp4 https://www.googleapis.com/upload/drive/v2/files

请帮我解决这个问题

最佳答案

您需要使用正确的语法。这是/v2 的工作版本。尽管我会建议您尽快移至/v3。 这将创建一个给定名称的文件夹。

使用版本/v2

wget  --header="Authorization: Bearer MY_TOKEN"  --header="Content-Type: application/json" --method=POST --body-data='{"title":"TemDir121", "mimeType": "application/vnd.google-apps.folder"}' 'https://www.googleapis.com/drive/v2/files' -O result.html

对于/v3

wget  --header="Authorization: Bearer MY_TOKEN"  --header="Content-Type: application/json" --method=POST --body-data='{"name":"TemDir", "mimeType": "application/vnd.google-apps.folder"}' 'https://www.googleapis.com/drive/v3/files' -O result.html

关于linux - 在对 Google Drive API 的请求正文中写什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38245412/

相关文章:

linux - 第一列中相同值的第二列和第三列之和

linux - 如何避免 sudo 字,用于由非 root 用户执行更高权限的命令

C 程序在从 Flask 服务器获得响应时挂起

javascript - 你什么时候想要更多/更少的http请求?

索引 API 403 权限被拒绝。无法验证 URL 所有权

google-api - 无法为 GMB 业务订阅发布/订阅推送通知

c - 用空字符替换 "\""

php - 通过不同服务器的 FTP PHP

java - 从 Java Servlet 返回字符串数组到 jQuery

search - 使用 Freebase 搜索服务进行多词搜索查询