Google Docs/Drive API does not permit a new docume

2019-05-12 08:31发布

问题:

We have identified an issue with the Google Docs/Drive APIs that is consistently reproducible, and appears to be a new bug introduced a few weeks ago. To see the issue, follow these steps:

  1. Create a brand new Google account, but do NOT do anything in that account (do not click on Drive to view Google Drive) -- just create it and close that window.
  2. Attempt to insert a new (empty) document via the Google Docs API (we use Zend GData for that) or the new Google Drive API.

Result: With old Google Docs API, the error "Expected response code 200, got 400. Unable to convert document" is thrown (which is meaningless when we are just creating a new document, not uploading something). With the new Google Drive API, the same thing produces the error "An error occurred: Error calling POST googleapis.com/drive/v2/files: (500) Internal Error"

This continues to happen until I go into that new Google account and click "Drive" to enter Google Drive. Something about doing that "initializes" Google Drive for that user, at which point the code to insert the new document works without any issue.

This only started happening recently (within the last few weeks). The same code has been in place for years without any problem in this scenario. In a school setting, where an administrator is creating new student accounts (as Google Apps for Education accounts), this issue shows up very frequently as they use our service. Is this going to be fixed? Is there a work-around? Help, Google API folks!

回答1:

A quick workaround would be:

Add to scopes: https://www.googleapis.com/auth/drive.apps.readonly

Before trying to create new doc, make a call to list apps installed $service->apps->listApps(); or list of files $service->files->listFiles();

Try and see if this works for you.