Uploading zip files to Google Docs API version 3: Permission issues

I’m having trouble uploading a tar.gz file to Google Docs using their API v3. The docs say any file type can be uploaded but I keep getting a 403 error saying I don’t have permission.

My code works fine with plain text docs and API v1 but not v3. I’m using ‘application/x-gzip’ as the mime type and set convert to false. Here’s a simplified version of my code:

$client = DocAPI::getClient(USER, PASS, AUTH_SERVICE);
$docs = new DocHandler($client);
$result = $docs->uploadArchive($file,
                'Archive: ' + $name,
                'application/x-gzip',
                'https://docs.google.com/feeds/default/private/full?v=3&convert=false');

I’m using a PHP framework for this. Am I missing something obvious? Could it be the mime type causing issues? Any help would be great!

I’ve dealt with similar upload issues using the Google Docs API. One thing that helped me was enabling the Google Drive API in the Google Cloud Console alongside the Docs API. Sometimes the permissions don’t carry over properly between the two.

Also, check if you’re using the correct authentication flow. For server-side apps, you’ll want to use a service account with domain-wide delegation. This gives you more control over permissions.

If those don’t work, try uploading to Google Drive first, then importing into Docs. It’s a bit of a workaround, but it solved some tricky mime type issues I had with compressed files.

Lastly, make sure your PHP version is up to date. Older versions sometimes have trouble with certain API calls. Good luck troubleshooting!

I encountered a similar challenge when working with the Google Docs API v3. In my experience, the issue often lies with the API permissions rather than the code itself. Have you verified that your API credentials have the necessary scope to upload files? Specifically, you might need the ‘https://www.googleapis.com/auth/drive.file’ scope.

Additionally, ensure you’re using the correct endpoint for v3. The URL in your code snippet looks more like v1 or v2. For v3, you should be using something like ‘https://www.googleapis.com/upload/drive/v3/files’.

Lastly, consider using the Google Drive API instead of the Docs API for file uploads, especially for non-document file types. It provides more robust support for various file formats and might resolve your permission issues.

hey mate, i had a similar issue. try changing the mime type to ‘application/octet-stream’ instead. that worked for me with zip files. also double check ur auth tokens are up to date, sometimes they expire and cause weird permission errors. good luck!