How to make HTTP requests to Google Drive API endpoints

I’m working on a Qt C++ application that uses OAuth2 to connect with Google Drive API. I can successfully make requests to get user info using the OAuth endpoint, but I’m struggling with the Drive API requests.

What works:
Basic OAuth requests work fine and return proper responses.

What I need help with:

  1. How do I retrieve a list of files and directories from Google Drive?
  2. What’s the correct way to create new folders using POST requests?

When I try to create a folder with a POST request, I keep getting parse errors with code 400. The response shows a “Parse Error” message but I can’t figure out what’s wrong with my request format.

Can someone share working examples of how to structure these API calls properly? I’d really appreciate any guidance on the correct request format and endpoints to use.

Thanks for any help!

I ran into the exact same issue when implementing Drive API calls in my Qt application last year. The problem was that I wasn’t including the Authorization header correctly in my requests after the initial OAuth authentication. Make sure you’re passing the access token in the Authorization header as “Bearer YOUR_ACCESS_TOKEN” for all Drive API calls. The token from your successful OAuth flow needs to be included in every subsequent request to the Drive endpoints. For retrieving files, I use GET requests to https://www.googleapis.com/drive/v3/files?fields=files(id,name,mimeType,parents) which gives you the essential file information. The fields parameter is important because it reduces response size and makes parsing easier. One thing that caught me off guard was token expiration. If your requests suddenly start failing after working initially, check if your access token has expired and needs refreshing using the refresh token from your OAuth flow.

The 400 parse error you’re encountering is typically caused by incorrect JSON formatting in your POST request body. When creating folders through the Drive API, you need to ensure your Content-Type header is set to “application/json” and your request body contains properly formatted JSON with the folder metadata.

For creating folders, use the endpoint https://www.googleapis.com/drive/v3/files with a POST request. The JSON body should include the folder name and specify the MIME type as “application/vnd.google-apps.folder”. Make sure there are no trailing commas or syntax errors in your JSON structure.

Regarding file listing, use GET requests to https://www.googleapis.com/drive/v3/files with optional query parameters like “q” for filtering. I encountered similar issues when I first implemented Drive API integration and found that logging the exact request headers and body helped identify formatting problems quickly.

check your json escaping in the request body - had same issue and turns out i was double-escaping quotes in the folder name field. also make shure you’re using the v3 api endpoints not v2, they changed the structure alot