如何以及何时使用刷新令牌与PHP谷歌日历API [英] how and when to use the refresh token with php google calender api

查看:127
本文介绍了如何以及何时使用刷新令牌与PHP谷歌日历API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在日历所有者授权后,我使用数据库中的刷新标记保存access_token。

当任何人显示日历页面时,我可以使用这一小部分代码

  $ client = new apiClient(); 
$ client-> setApplicationName(My Calendar);
$ client-> setAccessType('offline');
$ client-> setAccessToken($ _SESSION ['google'] ['access_token']);
$ calService = new apiCalendarService($ client);
$ optParams = array('timeMin'=> $ gstart,'timeMax'=> $ gend);
$ events = $ calService-> events-> listEvents($ _ SESSION ['google'] ['google_cal_id'],$ optParams);

我在文档中看到在某些时候我可能不得不使用刷新标记(我在数据库中)。
我不知道如何使用这个令牌和何时。在某个时候setAccessToken会抛出一个异常吗?什么是最好的测试方法
谢谢

解决方案

访问令牌在3600s或一个小时内过期。但是,您可以使用刷新令牌来获取新的访问令牌,而无需用户重新进行身份验证。

有关如何使用php获取刷新令牌的详细信息,请查看本文中接受的答案:
使用PHP脚本自动刷新令牌使用谷歌驱动器api



如果您使用REST API而不是PHP SDK,它基本上会将您的刷新令牌client_id,secret发送到 https://accounts.google.com/o/oauth2/token ,详见页面底部 here



刷新令牌不会过期,除非用户撤消它或者以编程方式撤销它。


I am using v3 of the php google calendar api.

After the calendar owner authorizes i save the access_token with the refresh token in the database.

When the calendar page is displayed by anyone i have this little bit of code that works

$client = new apiClient();
$client->setApplicationName("My Calendar");
$client->setAccessType('offline');
$client->setAccessToken( $_SESSION['google']['access_token'] );
$calService = new apiCalendarService($client);
$optParams = array('timeMin' => $gstart, 'timeMax'=> $gend);
$events = $calService->events->listEvents($_SESSION['google']['google_cal_id'], $optParams);

I have seen in the doc that at some point i may have to use the refresh token(which i have in the database.) What i do not know is how to use this token and when. Will setAccessToken thrown an exception at some point? What is the best way to test this as well Thanks

解决方案

The access token expires in 3600s or one hour. But you can use refresh token to get a new access token without user re-authenticate.

For details on how to get refresh token using php, check out the accepted answer in this post: Automatically refresh token using google drive api with php script

If you use the REST API instead of the PHP SDK, it's basically sending your refresh token, client_id, secret to https://accounts.google.com/o/oauth2/token as described at the bottom of the page here

Refresh token does NOT expire unless user revoke it or you programmatically revoke it.

这篇关于如何以及何时使用刷新令牌与PHP谷歌日历API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆