Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get Google client using access token

I already stored the access and refresh token in my database. I want get the google client using that. I don't know how to use it in below example

$client = Zend_Gdata_ClientLogin::getHttpClient('[email protected]', 'password', Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME);
$service = new Zend_Gdata_Spreadsheets($client);

// Get worksheet feed
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey('your spreadsheet key');
$feed = $spreadsheetService->getWorksheetFeed($query);

I want replace email and password with access token. Someone help me how to do that. I tried below. but I got only exception

Caught exception: Expected response code 200, got 401

and Stateless token expired

$client = Zend_Gdata_AuthSub::getHttpClient('ya29.XXXXXXX'); 

Another try,

$client = new Zend_Gdata_HttpClient();
$session_token =Zend_Gdata_AuthSub::getAuthSubSessionToken('ya29.XXXXXXX',$client);
$client->setAuthSubToken($sessionToken);

Caught exception: Token upgrade failed. Reason:

like image 838
Gowri Avatar asked May 28 '26 16:05

Gowri


1 Answers

I think you are mixing things up.

ClientLogin and AuthSub are different authentication APIs (both deprecated). The ClientLogin token expires after two weeks or earlier (see: https://developers.google.com/gdata/faq#clientlogin_expire). You can use the token as long as it does not expire by calling the setter setClientLoginToken of Zend_Gdata_HttpClient.

Example:

$client = Zend_Gdata_ClientLogin::getHttpClient('[email protected]', 'password', Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME);
$token = $client->getClientLoginToken();
//Save to DB / in session / whatever
$client = new Zend_Gdata_HttpClient();
$client->setClientLoginToken($token);
//Do stuff

You can also cache the whole HttpClient object with Zend_Cache.

AuthSub or OAuth 2.0 (better, but no classes provided by ZF) is maybe better for your needs, because the tokens do not expire (AuthSub) or can be refreshed (OAuth2)

Docs

AuthSub:

  • ZF Docs > http://framework.zend.com/manual/1.12/de/zend.gdata.authsub.html
  • Revoke unlimited token > https://developers.google.com/accounts/docs/AuthSub?hl=de#AuthSubRevokeToken

OAuth2:

  • Refresh tokens > https://developers.google.com/accounts/docs/OAuth2WebServer?hl=de#refresh
like image 186
BreyndotEchse Avatar answered May 31 '26 04:05

BreyndotEchse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!