Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP访问Google日历api_Php_Javascript_Json - Fatal编程技术网

使用PHP访问Google日历api

使用PHP访问Google日历api,php,javascript,json,Php,Javascript,Json,我对谷歌api有点困惑,尤其是谷歌日历api。似乎我找到的每个示例都希望用户通过返回URL进行连接和返回。我想做的就是用谷歌日历api在后台抓取信息,显示数据,甚至创建数据。我愿意使用Javascript/JSON或者通过PHP更好地实现这一点 以下是我发现的示例: <?php session_start(); require_once dirname(__FILE__).'/GoogleClientApi/Google_Client.php'; require_once dirname(

我对谷歌api有点困惑,尤其是谷歌日历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.';

我知道了。如果有人对它的工作原理感到好奇,无论您使用的是什么google API,您首先需要允许通过浏览器进行访问,除非您已经拥有访问令牌。在此之后,您可以从他们的库中提取所需的任何信息