问题描述
我已经在数据库中存储了访问和刷新令牌.我想使用它的谷歌客户端.我不知道如何在下面的示例中使用它
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
和无状态令牌已过期
$client = Zend_Gdata_AuthSub::getHttpClient('ya29.XXXXXXX');
另一种尝试,
$client = new Zend_Gdata_HttpClient();
$session_token =Zend_Gdata_AuthSub::getAuthSubSessionToken('ya29.XXXXXXX',$client);
$client->setAuthSubToken($sessionToken);
推荐答案
我认为您正在混淆.
ClientLogin和AuthSub是不同的身份验证API(均已弃用).ClientLogin令牌在两周或更早之后过期(请参阅: https://developers.google.com/gdata /faq#clientlogin_expire ).只要令牌没有过期,就可以使用它,方法是调用Zend_Gdata_HttpClient
的设置器setClientLoginToken
.
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
.
$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
您还可以使用Zend_Cache缓存整个HttpClient对象.
You can also cache the whole HttpClient object with Zend_Cache.
AuthSub或OAuth 2.0(更好,但ZF不提供任何类)可能会更好地满足您的需求,因为令牌不会过期(AuthSub)或可以刷新(OAuth2)
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)
AuthSub:
- ZF文档> http://framework.zend.com /manual/1.12/de/zend.gdata.authsub.html
- 撤销无限令牌> https://developers.google.com/accounts/docs/AuthSub?hl = de#AuthSubRevokeToken
- 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:
这篇关于使用访问令牌获取Google客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!