asimlqt / php-google-spreadsheet-client

A PHP library for accessing and manipulating Google Spreadsheets
Other
543 stars 154 forks source link

AccessToken service account #144

Closed samoum23 closed 8 years ago

samoum23 commented 8 years ago

I'm trying to access to the drive with the access token but i didn't success. This is my code public function indexAction() {

$client = new \Google_Client();
$client->setClientId("5d6c05b0215ae3a30ed95c64a73bbe7785974564");

$cred = new \Google_Auth_AssertionCredentials(
    "******@gmail.com",
    array('https://spreadsheets.google.com/feeds','https://docs.google.com/feeds'),
    file_get_contents("../app/config/google.p12")
);

$client->setAssertionCredentials($cred); 

if ($client->getAuth()->isAccessTokenExpired()) {
    $client->getAuth()->refreshTokenWithAssertion($cred);
}

$service_token = json_decode($client->getAccessToken());
return $service_token->access_token;

This is the error: Error refreshing the OAuth2 token, message: '{ "error" : "invalid_client", "error_description" : "The OAuth client was invalid." }' 500 Internal Server Error - Google_Auth_Exception

asimlqt commented 8 years ago

This library doesn't deal with OAuth, You'll have to ask this question on the official Google PHP client library page.