GET / POST requests Google Drive API

I am learning the Google Drive API and developing a program in Qt C ++ (using OAuth2), so I need to create queries, but I have not found how to do this.

For example, if I make a request - https://www.googleapis.com/oauth2/v1/userinfo?access_token=MY_ACCESS_TOKEN , everything works fine - I get a response.

Question: how to make a SIMILAR request for Google Drive?

1) how can I get a list of folders and files

2) how to 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 don’t understand

Any opinions / examples are welcome!

early

+3
source share
3 answers

Unfortunately, the Drive API does not allow you to list folders or files. The only way to get the file is to integrate it with the web interface of Google Drive or show the Google Picker to your user (only for web applications).

Once you have the file id, you can simply send the resolved GET request to the drive.files.get endpoint :

GET https://www.googleapis.com/drive/v1/files/id 

To insert a file (or folder) , file metadata should be included in the request body, and not as a request 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 above example, mimeType indicates that the inserted resource is a folder. Change mimeType to the MIME application type when inserting the file.

+3
source

You should use google APIs for this

Retrieving Collections List - Google Docs APIs 3.0

In OAuth 2.0 the playground just select the list of documents and Google Drive And you will get a complete list of operations:

 List FolderContent GET https://docs.google.com/feeds/default/private/full/{folderResouceId}/contents 

Do not forget to add the query parameter ?v=3 to the document list URI or add

 GData-Version: 3.0 

otherwise it will return an "Invalid request URI" .

0
source

We recommend that you read the api reference documents in the google driver in

https://developers.google.com/drive/v3/reference/files/list

I managed to use many api functions after the link above and using curl. But in fact, I recommend you try making HTTP requests with a tool like a postman. In any case, after receiving the access code following the link below

google file list

try the following command on the command line.

 curl -H 'GData-Version: 3.0' -H "Authorization: Bearer $ACCESS_TOKEN" \ https://www.googleapis.com/drive/v2/files?maxResults=$100 
0
source

All Articles