GET/POST requests Google Drive API

google-drive-api

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

Best Answer

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.

Related Topic