- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想构建一个脚本,通过 Google 日历 PHP 客户端检查经过身份验证的用户的 Google 日历。我能够构建一个简单的页面,让用户进行身份验证并授予日历事件权限。我收到一个 token ,然后通过以下方式获取 15 个即将举行的事件:
$googleCal = new Google_Service_Calendar($googleClient);
$results = $googleCal->events->listEvents($calendarId, $optParams);
但是我正在努力解决的是如何保存它,以便我可以让脚本每天检查它以查看是否添加了新事件。我认为我已经很接近了,只是努力冲过终点线。
谢谢!
--
更新,我正在尝试使用刷新 token ,这是我的代码:
public function checkRedirectCode()
{
if(isset($_GET['code']))
{
$this->client->authenticate($_GET['code']);
// $this->setToken($this->client->getRefreshToken());
$this->setToken($this->client->getAccessToken());
$this->storeUser($this->getPayload());
return true;
}
return false;
}
public function setToken($token)
{
$_SESSION['access_token'] = $token;
$this->client->setAccessToken($token);
}
我已经能够回显刷新 token ,所以我知道我得到了正确的刷新 token ,但每当我使用注释掉的字符串时,我都会收到错误。有什么想法吗?
最佳答案
为了使您的脚本能够在原始访问 token 的生命周期(仅持续一小时)之外被调用,您需要在初始授权期间检索并存储刷新 token ,然后使用它来生成新的访问权限每次脚本运行时都会生成 token 。
Access tokens have limited lifetimes. If your application needs access to a Google API beyond the lifetime of a single access token, it can obtain a refresh token. A refresh token allows your application to obtain new access tokens.
https://developers.google.com/identity/protocols/OAuth2#basicsteps (4. 如有必要,请刷新访问 token 。)
用户对您的应用进行身份验证后,将使用 code
查询字符串返回到您的重定向 URI。
以下是验证和获取刷新 token 的示例(这使用 Analytics,但对于其他服务应该相同):
$client = new Google_Client();
$client->setClientId('xxx');
$client->setClientSecret('xxx');
$client->setRedirectUri('xxx');
//authenticate with the code returned from google
$authenticate = $client->authenticate($_GET['code']);
//get the refresh token
$refreshToken = $client->getRefreshToken();
//store refresh token in database...
然后,当您运行日常脚本时,使用刷新 token (从数据库检索)生成新的访问 token :
$client = new Google_Client();
$client->setClientId('xxx');
$client->setClientSecret('yyy');
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
$client->refreshToken($user->refresh_token);
$newToken = $client->getAccessToken();
$client->setAccessToken($newToken);
关于php - Google Cal API - 检查事件的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35591224/
我试图在Powershell中使用COM对象创建一个Clearcase View 。 $ccViews="\\Hostname.global.mycompany.com\cc-view\" $View
我有下面的 HTML 表(cals 表),这里我需要一些 CSS 来显示屏幕截图(边框部分)中的输出。 To the Commissioner for Labour
我创建了一个包含 cal() 的表单,这样人们就可以选择选项,然后它会根据他们的选择计算答案。 但我想在末尾插入一个按钮来调用结果。因此,当人们选择了选项后,他们会单击提交按钮,系统会根据他们的选择给
我有一个 WPF 应用程序,它始终使用 MVVM 模式,没有代码隐藏,ViewModels 通过 MainViewModel 相互通信,MainViewModel 被注入(inject)到它们中。 最
我正在查看是否有人拥有将 HTML 表格转换为 CALS 的 XSLT。我发现了很多关于另一种方式(CALS 到 HTML)的 Material ,但不是来自 HTML。我认为以前可能有人这样做过,所
我正在尝试使用 d3.js 和 cal-heatmap.js 来创建可视化,但是无论我输入什么数据和格式,颜色都没有显示出来。我什至无法让最基本的默认可视化工作,也看不到问题的明确指标。我看到日历和单
我正在尝试创建一个 Prism (CAL) 框架(这是我第一次进入 CAL),并且在设计用于注册某个区域的菜单项的服务时遇到了困难。这是我到目前为止想出的...... /// /// Menu it
我们的 shell 程序的Window标记中有一个Region,向该区域添加内容会弹出另一个Window。 我们将ViewModels添加到Region Manager中,然后通过数据上下文附加V
我正在使用 D3 日历热图库 cal-heatmap 。 我有一个external我通过 jQuery .getJSON 回调函数获取的托管在 GitHub 上的 JSON 文件。我正在将 JSON
我使用 Google Calendar API 中的 list 方法来获取事件数据。 API 成功返回有关每个事件的基本信息,例如 start、end、location 和 attendees,但缺少
我想构建一个脚本,通过 Google 日历 PHP 客户端检查经过身份验证的用户的 Google 日历。我能够构建一个简单的页面,让用户进行身份验证并授予日历事件权限。我收到一个 token ,然后通
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 7 年前。 Improve
我正在尝试创建一个包含“Vertex3”实例的集合。我在创建该集合的行上遇到了一些问题: public Set> verticies = new Set>(); Eclipse 在等号右侧的“Set”
我使用下面的代码来获取用户当天的日历事件。 TODAY_MS 是一天开始的时间戳,ONE_DAY_MS 是以毫秒为单位的一天 (1000 * 60 * 60 * 24)。 但是,此代码仅获取即将发生的
我正在尝试创建一个 cal-heatmap带有 9 个类别的定性颜色图例(标记为 1-9)。我正在使用以下 CSS 来设置颜色: .q8{fill:rgb(141, 211, 199);} .q7{
我有一个显示上周数据的校准热图。每行代表一天,每列代表一个小时。我有日期标签,但没有时间标签。我怎样才能添加这些? var cal = new CalHeatMap(); cal.init({
我有一个 CAL 类型中断的峰值,每秒 20,000 次。如何找到在 SUSE11 上生成它们的进程? 谢谢! 最佳答案 您可以使用 SystemTap 轻松确定 它是一个动态探测系统,类似于 Sol
目前,我发现如果我写cal月年,我就会得到该月的日历。有没有办法返回这一天而不是获取完整的日历?除此之外,1752 年的日历是假的,没有半个月?任何想法表示赞赏。 最佳答案 date --date=
我正在尝试从这个 link 绘制calendar-heatmap . 我搜索了整个文档,但找不到任何data-format 的示例文件。 这是一个 link用于文档,但没有示例文件。 在文档中,我发现
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 7 年前。 Improve
我是一名优秀的程序员,十分优秀!