我只想要求用户一次访问帐户。我有令牌,但3600秒后令牌过期。请求授权仅使用第一次使用日历
这是我的代码(工作)“内”框架。有人可以告诉我该怎么办?
public function actionEvent() {
$client = new Google_Client();
$client->setApplicationName("Google Calendar Event");
$client->setAuthConfig(Yii::getAlias('@webroot') . '/calendar/client_secret.json');
$client->addScope(\Google_Service_Calendar::CALENDAR);
$client->setAccessType('offline');
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$calendar_service = new \Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event(array(
..events here..
));
$calendarId = 'primary';
$event = $calendar_service->events->insert($calendarId, $event);
var_dump($event->htmlLink);
} else {
$redirect_uri = $this->redirect(['pop/callback']);
}
}
public function actionCallback() {
$client = new Google_Client();
$client->setApplicationName("Google Calendar Event");
$client->setAuthConfigFile(Yii::getAlias('@webroot') . '/calendar/client_secret.json');
$client->setRedirectUri('http://localhost/pop/callback');
$client->addScope(\Google_Service_Calendar::CALENDAR);
if (!isset($_GET['code'])) {
$auth_url = $client->createAuthUrl();
$this->redirect($auth_url);
} else {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$this->redirect(['pop/event']);
}
}
session里面的,我有:
array (size=3)
'__flash' =>
array (size=0)
empty
'__id' => int 1
'access_token' =>
array (size=4)
'access_token' => string 'ya29.Ci-sf-asdfsadfsdfsd' (length=71)
'token_type' => string 'Bearer' (length=6)
'expires_in' => int 3599
'created' => int 1479326378
谢谢
基本上和你今天早些时候的另一个问题一样吗? http://stackoverflow.com/questions/40625179/add-event-to-google-calendar-using-api –
是的,但现在用代码。 –
你可以更新令牌 – 2016-11-16 20:54:29