Google 日历 API 保持帐户连接
Google calendar API keep account connected
我是 Google 日历 API(PHP / MySQL 和 codeigniter 3)的新手。
我想设置日历的双向同步。
我设法授权事件的恢复,还可以修改、删除和添加新事件。
但是过了一段时间我的token_access就失效了。
如何使我的应用程序不需要在每次启动时重新连接 Google 帐户?我想我还不太了解这个规则是如何工作的。
我是根据这个教程https://techarise.com/integrate-google-calendar-api-with-codeigniter-calendar-library/
如果你能就这个问题启发我?
非常感谢
But after a while my token_access is no longer valid.
这是正常现象,无法阻止您连接到 google 以获取您的凭据。
您实际上需要做的是 refresh your token,因此您不需要获得全新的 Authorization code
。
如果您想要更详细的解释以了解 OAuth2 工作流程在 google 中的工作原理,我建议您阅读 this page from the official documentation. And if you want to read the whole RFC of OAuth2 您也可以这样做。
尽管我强烈建议在 OAuth2 Playground 中使用和测试以查看您需要发出哪些实际 HTTP 请求才能刷新令牌。
TL;DR: 访问令牌在创建后过期,这是预期的。您需要使用刷新令牌来获取新的访问令牌。
感谢您的回答。
这使我能够编写此工作代码!
无论是电脑还是手机客户端,我的账号都是自动连接的,不用经过同意界面。
并且双向同步正确完成。
非常感谢你
public function getClientGoogle(){
if($this->dataUserCal->google_calendar == 'Oui'){
if ($this->googleapi->isAccessTokenExpired()) {
$this->googleapi->setAccessToken(json_decode($this->dataUserCal->data_token_google,true));
$r = $this->googleapi->getRefreshToken();
$token = $this->googleapi->fetchAccessTokenWithRefreshToken($this->googleapi->getRefreshToken());
$this->tokenAccessGoogle = $token['access_token'];
$this->db->set('access_key_google', $token['access_token']);
$this->db->set('data_token_google', json_encode($token));
$this->db->set('date_access_key_google',date('Y-m-d H:i:s'));
$this->db->where('id', $this->session->userdata('id_user'));
$this->db->update('users');
} else {
$this->tokenAccessGoogle = $this->dataUserCal->access_key_google;
}
}
}
我是 Google 日历 API(PHP / MySQL 和 codeigniter 3)的新手。 我想设置日历的双向同步。
我设法授权事件的恢复,还可以修改、删除和添加新事件。
但是过了一段时间我的token_access就失效了。 如何使我的应用程序不需要在每次启动时重新连接 Google 帐户?我想我还不太了解这个规则是如何工作的。
我是根据这个教程https://techarise.com/integrate-google-calendar-api-with-codeigniter-calendar-library/
如果你能就这个问题启发我?
非常感谢
But after a while my token_access is no longer valid.
这是正常现象,无法阻止您连接到 google 以获取您的凭据。
您实际上需要做的是 refresh your token,因此您不需要获得全新的 Authorization code
。
如果您想要更详细的解释以了解 OAuth2 工作流程在 google 中的工作原理,我建议您阅读 this page from the official documentation. And if you want to read the whole RFC of OAuth2 您也可以这样做。
尽管我强烈建议在 OAuth2 Playground 中使用和测试以查看您需要发出哪些实际 HTTP 请求才能刷新令牌。
TL;DR: 访问令牌在创建后过期,这是预期的。您需要使用刷新令牌来获取新的访问令牌。
感谢您的回答。 这使我能够编写此工作代码! 无论是电脑还是手机客户端,我的账号都是自动连接的,不用经过同意界面。 并且双向同步正确完成。 非常感谢你
public function getClientGoogle(){
if($this->dataUserCal->google_calendar == 'Oui'){
if ($this->googleapi->isAccessTokenExpired()) {
$this->googleapi->setAccessToken(json_decode($this->dataUserCal->data_token_google,true));
$r = $this->googleapi->getRefreshToken();
$token = $this->googleapi->fetchAccessTokenWithRefreshToken($this->googleapi->getRefreshToken());
$this->tokenAccessGoogle = $token['access_token'];
$this->db->set('access_key_google', $token['access_token']);
$this->db->set('data_token_google', json_encode($token));
$this->db->set('date_access_key_google',date('Y-m-d H:i:s'));
$this->db->where('id', $this->session->userdata('id_user'));
$this->db->update('users');
} else {
$this->tokenAccessGoogle = $this->dataUserCal->access_key_google;
}
}
}