0

I've been using the Google Drive API for several months to fetch the contents of a Google Drive Document that I created and export as HTML to embed within my web application.

Sample code:

$client = new Google_Client();
$client->setApplicationName('My App');
$client->setScopes(Google_Service_Drive::DRIVE_READONLY);
$client->setDeveloperKey(GOOGLE_DRIVE_API_KEY);
$client->setAccessType('offline');

$service = new Google_Service_Drive($client);

$files = $service->files->listFiles([
    'q'       => "'" . GOOGLE_DRIVE_RN_FOLDER_ID ."' in parents",
    'orderBy' => 'createdTime desc',
]);

foreach($files as $file)
{
    $response = $service->files->export(
        $file->id, 
        'text/html', 
        array(
            'alt' => 'media'
        )
    );

    $html = $response->getBody()->getContents();
}

This code broke last week and I can't figure out why. The $service->files->listFiles() method works successfully (I can see file names in the response), but the $service->files->export() method returns a 500 Internal Error. Sample response:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "internalError",
    "message": "Internal Error"
   }
  ],
  "code": 500,
  "message": "Internal Error"
 }
}

I also receive the same error when attempting to access the API URL directly in a web browser: https://www.googleapis.com/drive/v3/files/1-DTp74pyo5nnDyR9cWt_d7oi7OdS7JwAZ6ZrKSQ54p0/export?mimeType=text%2Fhtml&key={my_key}.

I tried re-generating API Keys, creating a new Project and generate a brand new API Key. I continue receiving the same error.

tehhowch
  • 9,645
  • 4
  • 24
  • 42
Lee Salminen
  • 900
  • 8
  • 18
  • Does it work for different files? If so, then the problem is with the recent changes to the files you run this on. There's not much, if anything, that we can do for "I didn't do anything and it broke" "questions". – tehhowch Apr 03 '18 at 23:04
  • 1
    Typical Google. Not surprised that none of the employees have replied yet. It makes me laugh. Error 500 simply means that Google is having issues with the server, try an exponential back off. That worked for me. However, there is a problem and the engineering team know what it is, they just won't say anything. – Morfinismo Apr 04 '18 at 13:39
  • Indeed. Typical Google – Lee Salminen Apr 04 '18 at 19:14

1 Answers1

0

Google has apparently changed it's API and the answer is apparently to use a service account, however I'm still waiting on updates for this.

This may answer your question but I haven't had any luck: Google Drive API's file Export endpoint is failing with API Key authentication?

If you get an answer let us know!

Camro
  • 98
  • 1
  • 9