php - Using a Service Account, getAccessToken() is returning null -
i running following php code, using client libraries found here: https://code.google.com/p/google-api-php-client/. not errors of code, when call getaccesstoken()
, returns null.
i have allowed access service account on personal calendar, , have granted full access project via api console.
any ideas?
require_once 'google-api-php-client/src/google_client.php'; const client_id = 'blahblahblah'; const service_account_name = 'blahblahblah@developer.gserviceaccount.com'; const key_file = 'path/to/privatekey.p12'; $google_client = new google_client(); // created initialized static dependencies $client = new google_oauth2(); // need google_oauth2 $key = file_get_contents(key_file); $client->setassertioncredentials( new google_assertioncredentials( service_account_name, array('https://www.googleapis.com/auth/calendar'), $key ) ); var_dump($client->getaccesstoken());
for reason, seemed work:
require_once 'google-api-php-client/src/google_client.php'; const client_id = 'blahblahblah'; const service_account_name = 'blahblahblah@developer.gserviceaccount.com'; const key_file = 'path/to/privatekey.p12'; const calendar_scope = "https://www.googleapis.com/auth/calendar"; $key = file_get_contents(key_file); $auth = new google_assertioncredentials( service_account_name, array(calendar_scope), $key ); $client = new google_client(); $client->setscopes(array(calendar_scope)); $client->setassertioncredentials($auth); $client->getauth()->refreshtokenwithassertion(); $accesstoken = $client->getaccesstoken(); $client->setclientid(client_id);
if can explain why worked, please edit answer or comment!
Comments
Post a Comment