Skip to content

Instantly share code, notes, and snippets.

@ianbarber
Created November 28, 2012 12:19
Show Gist options
  • Save ianbarber/4160842 to your computer and use it in GitHub Desktop.
Save ianbarber/4160842 to your computer and use it in GitHub Desktop.
Create hangout link via calendar
<?php
/*
* example usage:
* First call to get the url
* php calcreate.php
* After authorising, grab the code from the redirect URL
* php calcreate.php "long_code_value_from_oauth_callback"
* This will var_dump out the new calendar entry
*/
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_CalendarService.php';
$client = new Google_Client();
$client->setApplicationName('Hangout Schedule');
$client->setClientId('CLIENT_ID_GOES_HERE');
$client->setClientSecret('CLIENT_SECRET_GOES_HERE');
$client->setRedirectUri('http://localhost');
$client->setScopes("https://www.googleapis.com/auth/calendar");
$service = new Google_CalendarService($client);
$token_file = sys_get_temp_dir() . PATH_SEPARATOR . "gcalhang.tok";
if(file_exists($token_file)) {
$token = json_decode(file_get_contents($token_file));
$client->setAccessToken($token);
}
if($client->isAccessTokenExpired()) {
if($_SERVER['argc'] == 1) {
echo $client->createAuthUrl(), "\n";
exit();
} else {
$code = $_SERVER['argv'][1];
$client->authenticate($code);
file_put_contents($token_file, json_encode($client->getAccessToken()));
}
}
$event = new Google_Event();
$event->setSummary('Future Hangout');
$event->setLocation('The Internet!');
$start = new Google_EventDateTime();
$start->setDateTime('2012-12-19T20:00:00.000-07:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2012-12-19T20:25:00.000-07:00');
$event->setEnd($end);
$attendee1 = new Google_EventAttendee();
$attendee1->setEmail('ianbarber@example.com');
$attendees = array($attendee1);
$event->attendees = $attendees;
$createdEvent = $service->events->insert('primary', $event);
var_dump($createdEvent);
@Rahilgupta15
Copy link

hi i am getting the SSL error while click on the Accept Button after adding the attendees to the circles

@aijanai
Copy link

aijanai commented Aug 12, 2015

where is the hangout related code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment