3
votes

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

3

3 Answers

3
votes

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.

0
votes

You should use google docs API for that

Retrieving a list of collections - Google Documents List API version 3.0

In OAuth 2.0 Playground just select both Documents List and Google Drive And you will get full list of operations:

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

Don't forget to add the ?v=3 query parameter to the Document list URI or adding

GData-Version: 3.0

header, otherwise it will return "Invalid request URI".

0
votes

You advise you to look at the google drive api reference docs in

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

i succeeded using many api functions following link above and using curl. But actually i recommend you trying to do http requests with a tool like postman. Anyway after getting access code following the steps link below

list google drive files with curl

try to make following command in the command line.

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