[英]zend_gdata: Get google calendar if already logged in an application
我在YiiFramework中創建了一個具有兩個功能的應用程序。
1. Login to google
要登錄到Google,我已按照以下網站上的教程進行操作。
教程: https : //github.com/Nodge/yii-eauth
教程演示: http : //nodge.ru/yii-eauth/demo/login
2 Get calendar using Zend_Gdata Library
教程: http : //www.bcits.co.in/googlecalendar/index.php/site/install
教程演示: http ://www.bcits.co.in/googlecalendar/index.php/site/page?view= about
[第一步]我使用yii-eauth成功登錄到我的應用程序。
[第二步]當我需要使用日歷時,我會提供硬編碼的gmail ID和密碼。
我以這種方式訪問日歷。
<?php
$user = 'your gmail username';
$pass ='your gmail password';
Yii::app()->CALENDAR->login($user, $pass);
?>
googlecalendar.php文件中的login()。
public function login($user, $pass) {
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);// It uses hard-coded gmail/password to get login again
$calenderlist = $this->outputCalendarList($client);
$events = $this->outputCalendar($client);
$calendardate = $this->outputCalendarByDateRange($client, $startDate = '2011-05-01', $endDate = '2011-06-01');
.........
}
Zend_Gdata庫是否包含任何無需重新登錄即可自動獲取當前用戶日歷的函數(在此處進行硬編碼)。
卡住了。 感謝幫助。 謝謝
據我了解, Zend_Gdata_ClientLogin
為$client
設置了一些參數,這是返回的對象。 請參見該功能的以下摘錄:
if ($loginToken || $loginCaptcha) {
if ($loginToken && $loginCaptcha) {
$client->setParameterPost('logintoken', (string) $loginToken);
$client->setParameterPost('logincaptcha', (string) $loginCaptcha);
} else {
require_once 'Zend/Gdata/App/AuthException.php';
throw new Zend_Gdata_App_AuthException(
'Please provide both a token ID and a user\'s response ' .
'to the CAPTCHA challenge.');
}
}
您可以做的就是存儲該令牌或該$client
對象(這是Zend_Gdata_HttpClient
的實例)。 幾乎所有的Zend_Gdata組件都接受$client
參數。
查看Zend_Gdata_Calendar
的__construct()
方法:
因此,無論如何,您將需要與此邏輯類似的東西(對不起,我不熟悉Yii):
$client = Yii::app()->getClient();
if (!$client) {
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
Yii::app()->setClient($client);
}
當然, 您將必須以某種方式定義該getClient()
方法。
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.