Question

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?

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top