使用PHP访问Google日历api
Google calendar api access with PHP
我对google api有点困惑,尤其是google日历api。似乎我找到的每个示例都希望用户通过返回URL连接并返回。所有我想做的是在后台与谷歌日历api抓取信息,显示数据,甚至创建数据。我愿意这样做与Javascript/JSON或通过PHP最好。
下面是我找到的例子:
<?php
session_start();
require_once dirname(__FILE__).'/GoogleClientApi/Google_Client.php';
require_once dirname(__FILE__).'/GoogleClientApi/contrib/Google_AnalyticsService.php';
$scriptUri = "http://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF'];
$client = new Google_Client();
$client->setAccessType('online'); // default: offline
$client->setApplicationName('My Application name');
$client->setClientId('INSERT HERE');
$client->setClientSecret('INSERT HERE');
$client->setRedirectUri($scriptUri);
$client->setDeveloperKey('INSERT HERE'); // API key
// $service implements the client interface, has to be set before auth call
$service = new Google_AnalyticsService($client);
if (isset($_GET['logout'])) { // logout: destroy token
unset($_SESSION['token']);
die('Logged out.');
}
if (isset($_GET['code'])) { // we received the positive auth callback, get the token and store it in session
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
}
if (isset($_SESSION['token'])) { // extract token from session and configure client
$token = $_SESSION['token'];
$client->setAccessToken($token);
}
if (!$client->getAccessToken()) { // auth call to google
$authUrl = $client->createAuthUrl();
header("Location: ".$authUrl);
die;
}
echo 'Hello, world.';
我明白了。如果有人好奇这是如何工作的,无论你正在使用的谷歌API,你首先需要允许通过浏览器访问,除非你已经有一个访问令牌。在此之后,您可以从他们的库中提取您需要的任何信息。
相关文章:
- 谷歌日历 api 调用可以在角度工厂内返回承诺吗?
- Google 日历 API V3 会解决与会者和创建者 Java 脚本问题
- 使用Java脚本访问多个Google日历-Google日历API
- 谷歌日历API v3推送通知不尊重timeMax或timeMin
- 在谷歌日历API的events.list的响应中查找日历所有者的电子邮件
- 为什么此 Google 日历 API 请求不返回开始时间等事件数据
- 向 Google 日历 API 发出服务器到服务器的请求
- Google 日历 API 在尝试获取我的所有日历事件时返回 404
- 如何使用 JavaScript 从 Google 日历 (API) 获取今天的事件
- Google 日历 API 密钥不允许通过简单的 GET 请求访问公共日历
- 以编程方式切换谷歌日历 API 的忙/闲事件状态
- Google 日历 API v3 calendar.events.list 并在 javascript 中使用 time
- 向谷歌日历 API 发出 ajax 请求
- 从谷歌日历 API 中的事件列表中检索实例
- Google 日历 API 将日期、时间和事件名称返回给 Javascript
- 是否可以在谷歌日历API中发送/插入事件数组
- Office 365日历API基于创建事件触发对应用程序的调用
- 谷歌日历API v3 javascript格式
- node.js(谷歌日历api,mongojs)中循环的顺序错误
- 如何使用Google日历API检索每月重复事件的实例