0

私はグーグルAPI、特にグーグルカレンダーAPIについて少し混乱しています。私が見つけたすべての例では、ユーザーが接続してリターンURLを介して戻ることを望んでいるようです。私がやりたいのは、Googleカレンダー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.';
4

1 に答える 1

0

私はこれを理解しました。使用している Google API が何であれ、これがどのように機能するかについて誰かが興味を持っている場合は、アクセス トークンをまだ持っていない限り、最初にブラウザからのアクセスを許可する必要があります。この後、ライブラリから必要な情報を引き出すことができます。

于 2013-01-12T14:13:24.360 に答える