GET / POST请求Google Drive API [英] GET/POST requests Google Drive API
问题描述
我目前学习Google Drive API并在Qt C ++中开发程序(使用OAuth2),所以我需要构建查询,但我找不到如何去做。
例如,如果我提出请求 - https:// www .googleapis.com / oauth2 / v1 / userinfo?access_token = MY_ACCESS_TOKEN ,一切正常 - 我收到回复。
问题是:如何使一个简单的Google Drive请求?
1)如何获取文件夹和文件的列表
2)如何创建文件夹/文件
等。
https://www.googleapis .com / drive / v1 / files& title = pets& mimeType = application / vnd.google-apps.folder
我得到
error:{
errors:[{
domain:global,
reason:parseError,
message:Parse Error
}
],
代码:400,
消息:解析错误
}
}
如何获取文件夹列表和文件,例如,等等,我不明白
欢迎任何意见/例子!
谢谢提前
遗憾的是,Drive API不允许您列出文件夹或文件。检索文件的唯一方法是与云端硬盘网络用户界面集成或显示 Google Picker 给您的用户(仅限网络应用程序)。
一旦您拥有文件ID,您只需将授权的GET请求发送到 drive.files.get endpoint :
GET https://www.googleapis.com/drive/v1/files/id
要插入文件(或文件夹),文件的元数据将成为包含在请求体中,而不是查询参数:
POST https://www.googleapis.com/drive/v1/文件
Authorization:Bearer {ACCESS_TOKEN}
Content-Type:application / json
...
{
title:pets,
parentsCollection:[{id:0ADK06pfg}]
mimeType:application / vnd.google -apps.folder
}
在上面的例子中, mimeType
指定被插入的资源是一个文件夹。插入文件时将 mimeType
更改为您的应用程序MIME类型。
I learning currently Google Drive API and developing program in Qt C + + (using OAuth2), so I need to build queries, but I'm not found how to do it.
For example, if I make a request - https://www.googleapis.com/oauth2/v1/userinfo?access_token=MY_ACCESS_TOKEN, everything is working OK - I get the reply.
Question is: how to make a SIMILAR request for the Google Drive?
1) how can I get a list of folders and files
2) how can I create a folder / file etc.
For example, in a POST request "https://www.googleapis.com/drive/v1/files&title=pets&mimeType=application/vnd.google-apps.folder"
I get
"error": { "errors": [{ "domain": "global", "reason": "parseError", "message": "Parse Error" } ], "code": 400, "message": "Parse Error" } }
how to get a list of folders and files, for example, etc., I do not understand
Any opinions/examples are welcome!
thanks in advance
Unfortunately, the Drive API doesn't let you list folders or files. The only way to retrieve a file is by integrating with the Drive web UI or showing a Google Picker to your user (web app only).
Once you have a File ID, you can simply send an authorized GET request to the drive.files.get endpoint:
GET https://www.googleapis.com/drive/v1/files/id
To insert a file (or a folder), the File's metadata is to be included in the request body, not as query parameter:
POST https://www.googleapis.com/drive/v1/files
Authorization: Bearer {ACCESS_TOKEN}
Content-Type: application/json
...
{
"title": "pets",
"parentsCollection": [{"id":"0ADK06pfg"}]
"mimeType": "application/vnd.google-apps.folder"
}
In the example above, the mimeType
specifies that the resource being inserted is a folder. Change the mimeType
to your application MIME type when inserting a file.
这篇关于GET / POST请求Google Drive API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!