I’m working on a C++ application using the Qt framework and trying to implement Google Drive API functionality with OAuth2 authentication. While I can successfully make basic OAuth requests to get user information, I’m struggling with the proper syntax for Drive API calls.
I can retrieve user data just fine, but when I attempt to interact with Google Drive, my requests keep failing. Specifically, I need help with:
1) Retrieving file and folder listings from Drive
2) Creating new folders and files
When I try to create a folder using a POST request, I keep receiving parse errors with status code 400. The response indicates there’s an issue with how I’m formatting the request parameters.
Could someone provide examples of properly formatted GET requests for listing Drive contents and POST requests for creating folders? I’m particularly confused about the correct URL structure and parameter formatting for these operations.
Any code samples or guidance would be really helpful. Thanks!
Your issue is probably with the request structure. Drive API v3 needs exact endpoint URLs. For folders, hit https://www.googleapis.com/drive/v3/files with POST and use this JSON: {“name”: “YourFolderName”, “mimeType”: “application/vnd.google-apps.folder”}. That’s it - don’t add extra fields. Qt’s QNetworkRequest sometimes throws in headers Google doesn’t like, so check you’re not accidentally sending form data or random headers. File listings use the same URL with GET - add q parameters for filtering if you need them. Also check your OAuth scope has proper Drive permissions. I got burned by this early on - auth errors that looked like parsing issues.
Your 400 errors are probably from misconfigured content-type headers and the formatting of your request body. For Google Drive API operations, ensure that your POST requests have the content type set to “application/json” and that you are correctly escaping the JSON payload. When creating folders, you should send a raw JSON object that includes the folder name and set the mimeType to “application/vnd.google-apps.folder”. For retrieving file listings, use a GET request to “https://www.googleapis.com/drive/v3/files” while placing your OAuth token in the Authorization header formatted as “Bearer [token]”. Also, confirm that your Qt HTTP client isn’t automatically altering your JSON into form data; this can often lead to those parsing issues.
check if your OAuth token expired - expired tokens throw weird 400s that look like parsing issues. also make sure you’re not double-encoding the JSON payload in Qt. it’s a common issue with QNetworkAccessManager. for basic file listing, just GET /drive/v3/files with your bearer token. no body needed.
This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.