我正在尝试通过 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/