문제

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?

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top