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.