Ah the problem seems to be that I'm using the old Google Docs API and should migrate over to the Google Drive SDK. D'oh!
Google Drive API 401 when trying to download a file
-
12-01-2022 - |
문제
I'm using the google-api-php-client to get the URL for a document on my Google Drive. The URL works correctly when I paste it into my browser and I can download the file.
However, in my PHP app I always get a 401. Here's my code:
private function _get_document_contents($url)
{
// prepare opts
$opts = array(
'http' => array(
'method' => 'GET',
'header' => "Gdata-version: 3.0\r\nAuthorization: Bearer " . $this->_token . "\r\n"
)
);
// get the doc
return file_get_contents($url . '&exportFormat=html&format=html', false, stream_context_create($opts));
}
I've tried changing Bearer
to OAuth
(that's what OAuth 2.0 playground uses) but both fail.
Any ideas?
해결책
제휴하지 않습니다 StackOverflow