4

Google カレンダーにイベントを挿入するにはどうすればよいですか?

このガイドを使用しています: https://developers.google.com/google-apps/calendar/v3/reference/events/insert

例のセクションには、次の php コードがあります。

$event = new Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new EventDateTime();
$start->setDateTime('2011-06-03T10:00:00.000-07:00');
$event->setStart($start);
$end = new EventDateTime();
$end->setDateTime('2011-06-03T10:25:00.000-07:00');
$event->setEnd($end);
$attendee1 = new EventAttendee();
$attendee1->setEmail('attendeeEmail');
// ...
$attendees = array($attendee1,
                   // ...
                  );
$event->attendees = $attendees;
$createdEvent = $service->events->insert('primary', $event);

echo $createdEvent->getId();

しかし、$service が定義されていないため、致命的なエラーが発生します。$service を初期化してこれを機能させる方法を誰か教えてもらえますか?

4

5 に答える 5

3

Google API v3 PHP クライアントの最新バージョンでは、使用する必要があります

$event = new Google_Event(); 

それ以外の

$event = new Event();

また、

$start = new Google_EventDateTime();

それ以外の

$start = new EventDateTime();

そしてもちろん、必要な定義は異なります。これを使用してください:

require_once '../src/Google_Client.php';
require_once '../src/contrib/Google_CalendarService.php';
于 2013-09-18T15:38:29.733 に答える
2
$service = new apiCalendarService($apiClient);

詳細については、 https://developers.google.com/google-apps/calendar/instantiate (右上の PHP ソースに切り替えます) を参照してください。

于 2013-03-14T13:37:43.700 に答える
0

このページに記載されています。コードは以下にコピーされます。

src/config.php

global $apiConfig;
$apiConfig = array(
  // Site name to show in Google's OAuth authentication screen
  'site_name' => 'www.example.org',

  // OAuth2 Setting, you can get these keys on the API Access tab on
  // the Google APIs Console
  'oauth2_client_id' => 'YOUR_CLIENT_ID',
  'oauth2_client_secret' => 'YOUR_CLIENT_SECRET',
  'oauth2_redirect_uri' => 'YOUR_REDIRECT_URL',

  // The developer key; you get this from the Google APIs Console
  'developer_key' => 'YOUR_DEVELOPER_KEY',

  // Which Authentication, Storage and HTTP IO classes to use.
  'authClass' => 'apiOAuth2',

  // Definition of service specific values like scopes, OAuth token URLs, etc
  'services' => array(
      'calendar' => array('scope' => 'https://www.googleapis.com/auth/calendar'),
  )
);

あなたのスクリプト

session_start();

require_once "../src/apiClient.php";
require_once "../src/contrib/apiCalendarService.php";

$apiClient = new apiClient();
$apiClient->setUseObjects(true);
$service = new apiCalendarService($apiClient);

if (isset($_SESSION['oauth_access_token'])) {
  $apiClient->setAccessToken($_SESSION['oauth_access_token']);
} else {
  $token = $apiClient->authenticate();
  $_SESSION['oauth_access_token'] = $token;
}
于 2013-03-14T13:40:26.487 に答える
-1
full code for calendar:
this session has all 

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require_once '../../src/Google_Client.php';
require_once '../../src/contrib/Google_CalendarService.php';
//require_once '../../src/vendor/autoload.php';
session_start();

print_r($_SESSION);

$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Starter Application");

// Visit https://code.google.com/apis/console?api=calendar to generate your
// client id, client secret, and to register your redirect uri.
// $client->setClientId('insert_your_oauth2_client_id');
// $client->setClientSecret('insert_your_oauth2_client_secret');
// $client->setRedirectUri('insert_your_oauth2_redirect_uri');
// $client->setDeveloperKey('insert_your_developer_key');
$cal = new Google_CalendarService($client);
if (isset($_GET['logout'])) {
  unset($_SESSION['token']);
}

if (isset($_GET['code'])) {
  $client->authenticate($_GET['code']);
  $_SESSION['token'] = $client->getAccessToken();
  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}

if (isset($_SESSION['token'])) {
  $client->setAccessToken($_SESSION['token']);
}

if ($client->getAccessToken()) {
  $calList = $cal->calendarList->listCalendarList();
  print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";


 $_SESSION['token'] = $client->getAccessToken();
} else {
  $authUrl = $client->createAuthUrl();
  print "<a class='login' href='$authUrl'>Connect Me!</a>";
}



?>
于 2016-09-14T07:15:11.073 に答える