Closed GoogleCodeExporter closed 8 years ago
sorry,after creating services object it's working fine .
Original comment by p.v.vidy...@gmail.com
on 6 Mar 2012 at 10:25
Hey P.V.,
There's an excellent code snippet demonstrating how you can insert an event
using the Calendar API here:
http://code.google.com/apis/calendar/v3/using.html#creating_events
Make sure you press the "PHP" tab within that page.
Original comment by chirags@google.com
on 7 Mar 2012 at 7:34
Ah, I just saw your comment. I'm glad it is working now!
Original comment by chirags@google.com
on 7 Mar 2012 at 7:35
hi p.v.vidy...@gmail.com,
can give the exact code for that. it will help me for lot...........
Original comment by danials...@gmail.com
on 27 May 2012 at 12:05
hi p.v.vidyullatha@gmail.com,
check my code, if you find any mistake, please solve it..
<?php
<?php
require_once '../../src/apiClient.php';
require_once '../../src/contrib/apiCalendarService.php';
session_start();
$client = new apiClient();
$client->setApplicationName("Calendar API Project");
// 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 apiCalendarService($client);
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate();
$_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>";
}
$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();
?>
Original comment by danials...@gmail.com
on 27 May 2012 at 12:08
hi i am receive below error,
Fatal error: Call to a member function insert() on a non-object in
D:\xampp\htdocs\my_work\google-client_api\examples\calendar\simple.php on line
55
Original comment by testing....@gmail.com
on 27 May 2012 at 1:48
same problem
someone has found the solution ?
Original comment by alex.tal...@mdpqualite.fr
on 21 Jun 2012 at 2:26
In my case, it just says internal server error and happens at the very
$calendar->events->insert line. How can i tell what could be wrong? I followed
the google developers example.
Original comment by leadmana...@tamborrel.com
on 24 Aug 2012 at 4:34
Ok, people, the Google API examples are WRONG. Here's what I did:
Here's my code:
<?php
//Note: this code is simplified for easy reading and quick understanding
//Read my comments for places where the Google API examples were wrong
require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_CalendarService.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("App Name");
// Visit https://code.google.com/apis/console?api=calendar to generate your
// client id, client secret, and to register your redirect uri.
$client->setClientId('clientID');
$client->setClientSecret('clientSecret');
$client->setRedirectUri('redirectURI');
$client->setDeveloperKey('developerKey');
$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_r(get_declared_classes()); //This will dump the data of all declared classes so you can see what you have to work with
print "<br/><br/>";
if(isset($_POST['action']))
{
$action = $_POST['action'];
if($action == "addCalEvent")
{
$title = $_POST["title"];
$desc = $_POST["desc"];
$calID = $_POST["calID"];
//Set the Event data
$event = new Google_Event(); //note in the API examples it calls Event(). Apparently, they changed it and didn't update examples.
$event->setSummary('$desc');
$event->setLocation('Somewhere');
$start = new Google_EventDateTime(); //note in the API examples it calls EventDateTime().
$start->setDateTime('2012-12-24T10:00:00.000-07:00');
$event->setStart($start);
$end = new Google_EventDateTime(); //note in the API examples it calls EventDateTime().
$end->setDateTime('2012-12-24T10:25:00.000-07:00');
$event->setEnd($end);
$attendee1 = new Google_EventAttendee(); //note in the API examples it calls EventAttendee().
$attendee1->setEmail('addenteeEmail'); //make sure you actually put an email address in here
// ...
$attendees = array($attendee1,
// ...
);
$event->attendees = $attendees;
//Create the Event
//In the API examples it says "$createdEvent = $service->events->insert('primary', $event);"
//However, notice that our service is named $cal (see above declaration), which is an instance of Google_CalendarService
$createdEvent = $cal->events->insert('primary', $event);
//echo $createdEvent->getId(); //This line is still broken for me...not sure what to do
}
}
print "<h1>Add Item To Calendar</h1>";
print "<form action='simple_cal_ex.php' method='POST'>";
print "Title: <input type='text' name='title' id='title'><br/>";
print "Desc: <input type='text' name='desc' id='desc'></br>";
print "Select Calendar: <select name='calID' id='chooseCal'>";
for($i=0; $i < count($calList['items']); $i++)
{
print "<option value=".$calList['items'][$i]['id']."'>".$calList['items'][$i]['summary']."</option>";
}
print "</select></br>";
print "<input type='hidden' name='action' value='addCalEvent'>";
print "<input type='submit' value='Submit'>";
print "</form>";
//Dumps Calendar Data so you can see what you're working with
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>";
}
?>
Original comment by JRPrat...@gmail.com
on 24 Dec 2012 at 11:31
Unsure whether this is still relevant, but $createdEvent returns an array.
$createdEvent['id'] should return the correct value.
Original comment by ahow...@howdens.net.au
on 13 Jan 2013 at 10:29
Hello!
I create new event at localhost then have eror
Fatal error: Uncaught exception 'Google_IOException' with message 'HTTP Error:
(0) Could not resolve host: accounts.google.com; Host not found' in
C:\Ampps\www\test\google-api-php-client\src\io\Google_CurlIO.php:128 Stack
trace: #0
C:\Ampps\www\test\google-api-php-client\src\auth\Google_OAuth2.php(261):
Google_CurlIO->makeRequest(Object(Google_HttpRequest)) #1
C:\Ampps\www\test\google-api-php-client\src\auth\Google_OAuth2.php(239):
Google_OAuth2->refreshTokenRequest(Array) #2
C:\Ampps\www\test\google-api-php-client\src\auth\Google_OAuth2.php(216):
Google_OAuth2->refreshToken('1/yQyjIydNub7_R...') #3
C:\Ampps\www\test\google-api-php-client\src\service\Google_ServiceResource.php(1
66): Google_OAuth2->sign(Object(Google_HttpRequest)) #4
C:\Ampps\www\test\google-api-php-client\src\contrib\Google_CalendarService.php(4
94): Google_ServiceResource->__call('insert', Array) #5
C:\Ampps\www\test\google-plus-access.php(56):
Google_EventsServiceResource->insert('primary', Object(Google_Event)) #6
C:\Ampps\www\test\index.php(2): include in
C:\Ampps\www\test\google-api-php-client\src\io\Google_CurlIO.php on line 128
Please Help me
Original comment by phiho2...@gmail.com
on 20 Mar 2013 at 4:48
Hello! I create a new event and I have the following error:
PHP Notice: Undefined variable: cal in /var/www/xxxxxxxxxx/xxxx/xxxx.php on
line 30, referer: http://localhost/.......
The problem is in line $createdEvent = $cal->events->insert('primary', $event);
I tried to replace $service with $calendarService or $service but nothing
changes.
Please can you help me?
Original comment by m.kypria...@gmail.com
on 30 Apr 2013 at 8:51
Hi, I wanna to add event on my friend calendar who share his calendar with
me.Please let me know how can I add the event on his calendar ?
Original comment by vishal.d...@gmail.com
on 15 May 2013 at 1:28
require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_PredictionService.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Google Prediction API PHP Starter Application");
// Visit https://code.google.com/apis/console/?api=prediction to generate
// your oauth2_client_id, oauth2_client_secret, and to register your
// oauth2_redirect_uri.
$client->setClientId('');
$client->setClientSecret('');
$client->setRedirectUri('');
// $client->setDeveloperKey('insert_your_developer_key');
$client->setScopes(array('https://www.googleapis.com/auth/prediction'));
$predictionService = new Google_PredictionService($client);
$trainedmodels = $predictionService->trainedmodels;
if (isset($_REQUEST['logout'])) {
unset($_SESSION['access_token']);
}
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['access_token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['access_token'])) {
$client->setAccessToken($_SESSION['access_token']);
}
if ($client->getAccessToken()) {
$status = "Logged In";
} else {
$status = "Logged Out";
$authUrl = $client->createAuthUrl();
}
?>
Fatal error: Call to a member function makeRequest() on a non-object in
C:\Program Files\Apache
Group\Apache2\htdocs\church.loc\public_html\src\auth\Google_OAuth2.php on line
97
Help please for a couple of days, I can not solve this problem, e etot code
honestly skapiroval example of Google Quick Start
Original comment by Bekeshe...@gmail.com
on 19 Sep 2013 at 2:38
I got my code working Thanks to http://code.google.com/u/104184936238051917009/
The #9th Post on here...
<?php
require_once '../google-api-php-client/src/Google_Client.php';
require_once '../google-api-php-client/src/contrib/Google_CalendarService.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Event Creator");
$client->setClientId('MY CLIENT ID ADDRESS IS HERE');
$client->setClientSecret('MY CLIENT SECRET KEY IS HERE');
$client->setRedirectUri('http://localhost/phpt/caladd.php');
$client->setDeveloperKey('MY API KEY IS HERE');
$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_r(get_declared_classes()); //This will dump the data of all declared classes so you can see what you have to work with
//print "<br/><br/>";
if(isset($_POST['action']))
{
$action = $_POST['action'];
if($action == "addCalEvent")
{
$title = $_POST["title"];
$desc = $_POST["desc"];
$calID = $_POST["calID"];
$locat = $_POST["locat"];
$from = $_POST["from"];
$until = $_POST["until"];
//Set the Event data
$event = new Google_Event(); //note in the API examples it calls Event(). Apparently, they changed it and didn't update examples.
$event->setSummary($title);
$event->setDescription($desc);
$event->setLocation($locat);
$start = new Google_EventDateTime();
$start->setDateTime($from);
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime($until);
$event->setEnd($end);
$attendee1 = new Google_EventAttendee();
$attendee1->setEmail('addenteeEmail');
// ...
//$attendees = array($attendee1,
// ...
// );
//$event->attendees = $attendees;
$createdEvent = $cal->events->insert('MY CALENDARS DIRECT ID IS HERE@group.calendar.google.com', $event);
echo $createdEvent->getId();
}
}
// This is the form
print "<div style='width:100%;height:100%;'><div style='width:550px;height:320px;text-align:center;margin:200px auto;background-color:#f0ffff;border:1px solid black;'><div style='padding:50px;'><table>";
print "<form action='caladd.php' method='POST'>";
print "<tr><td>Title: </td><td><input type='text' name='title' id='title'></td></tr>";
print "<tr><td>Desc: </td><td><input type='text' name='desc' id='desc'></td></tr>";
print "<tr><td>Location: </td><td><input type='text' name='locat' id='locat'></td></tr>";
print "<tr><td colspan='2'>Date Format: YYYY-MM-DDTHH:MM:SS.000-00:00</td></tr>";
print "<tr><td>From: </td><td><input type='text' name='from' id='from'></td></tr>";
print "<tr><td>To: </td><td><input type='text' name='until' id='until'></td></tr>";
print "<tr><td>Select Calendar: </td><td><select name='calID' id='chooseCal'>";
// this is the auto populating selector
for($i=0; $i < count($calList['items']); $i++)
{
print "<option value=".$calList['items'][$i]['id']."'>".$calList['items'][$i]['summary']."</option>";
}
print "</select></br></td></tr>";
print "<input type='hidden' name='action' value='addCalEvent'>";
print "<tr><td colspan='2'><div style='text-align:right;'><input type='submit' value='Submit'></div></td></tr>";
print "</form>";
print "</table></div></div></div>";
//Dumps Calendar Data so you can see what you're working with
//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>";
}
?>
Original comment by joshthom...@gmail.com
on 19 Feb 2014 at 4:20
how i remove the error Call to a member function insert() on a non-object
Original comment by subhanul...@gmail.com
on 27 Jun 2014 at 12:09
how i initialize the server object and mention the file need to include for the
initialize the server object
Original comment by subhanul...@gmail.com
on 27 Jun 2014 at 12:12
Hi,
Getting PHP Fatal error: Call to undefined method Google_Http_Request::getId()
I like to insert an event into my Google Calender through form submission from
a website. I have tried OAuth as service account. I have also managed the
permission of my calender.
#################################
My Code
################################
<?php
require_once "google-api-php-client/src/Google/Client.php";
require_once "google-api-php-client/src/Google/Service/Calendar.php";
//
$client = new Google_Client();
$client->setUseBatch(true);
$client->setApplicationName("my calender name");
$client->setClientId("client id from oAuth");
$client->setAssertionCredentials(
new Google_Auth_AssertionCredentials(
"910956588975-oievltkhj9mi20rsv6r8sf4m6am8v0nn@developer.gserviceaccount.com",
array(
"https://www.googleapis.com/auth/calendar"
),
file_get_contents("certificate/create calender event-b614bfc034be.p12")
)
);
//
$service = new Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event();
$event->setSummary('Event 1');
$event->setLocation('Somewhere');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2014-11-25T10:00:00.000+01:00');
//$start->setTimeZone('Europe/London');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2014-11-25T15:25:00.000+01:00');
//$end->setTimeZone('Europe/London');
$event->setEnd($end);
$calendar_id = "usf2b8tgl5cjfc06gbj2kkos70@group.calendar.google.com";
//
$new_event = null;
//
try {
$new_event = $service->events->insert($calendar_id, $event);
$new_event_id= $new_event->getId();
} catch (Google_ServiceException $e) {
syslog(LOG_ERR, $e->getMessage());
}
//
$event = $service->events->get($calendar_id, $new_event->getId());
//
if ($event != null) {
echo "Inserted:";
echo "EventID=".$event->getId();
echo "Summary=".$event->getSummary();
echo "Status=".$event->getStatus();
}
//...><a href=$url?logout>Logout</a></font>";
###########################################################
if you guys have any clue, please suggest
Original comment by sudipban...@gmail.com
on 25 Nov 2014 at 5:02
Original issue reported on code.google.com by
p.v.vidy...@gmail.com
on 6 Mar 2012 at 10:13