Authenticating to Google Calendar API via Wordpress

191 views
Skip to first unread message

Christopher Mueller

unread,
Feb 5, 2013, 2:14:38 AM2/5/13
to google-api...@googlegroups.com
Hi guys, I'm having a tough time trying to get my WordPress site to authenticate into Google Calendar. The following code authenticates and can get/list/add events to my google calendar perfectly as a stand-alone php file on my localhost, however when I copy the code into my Wordpress files (I put it in at the top of header.php, though perhaps this is a bad idea?), I get the infamous php result Fatal error: Exception thrown without a stack frame in Unknown on line 0.
Has anyone interfaced with this before and knows what to do, or knows how to at least get around the Fatal error? Thanks in advance.

<?php

require_once 'path/to/Google_Client.php';
require_once 'path/to/Google_CalendarService.php';

define('SERVICE_ACCOUNT_NAME', 'XX...@developer.gserviceaccount.com');
define('KEY_FILE', '/path/to/keyfile/XXXXX-privatekey.p12');

$client = new Google_Client();
$client->setApplicationName("Name");
$client->setUseObjects(true);

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

$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new Google_AssertionCredentials( SERVICE_ACCOUNT_NAME, $scopes, $key));

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

$cal = new Google_CalendarService($client);
$fetchedEvent = (array)$cal->events->get('calendarID', 'eventID');

?>

Geoff Hoffman

unread,
Feb 5, 2013, 10:43:29 AM2/5/13
to google-api...@googlegroups.com
Build your functionality as a custom plugin. Or try to create the features inside of functions.php and use built-in WordPress variables & functions to locate the files & include them, e.g. get_template_directory( ). Also due to how WordPress loads (sometimes more than once), you may need to surround each function/class with if( ! function_defined( 'function_name' )) { // function definition }  HTH -



Geoff Hoffman
Solutions Architect & LAMP Engineer


--
You received this message because you are subscribed to the Google Groups "google-api-php-client" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-api-php-c...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


Connect with us on twittergoogle+facebook, or linkedin.

Catch our next training in Chicago Feb 4 - 8Boston Feb 11 - 15St Louis Feb 25 - Mar 1Vancouver Mar 4 - 8 or See All.

This email, including any attachments, is for the sole use of the intended recipient and may contain confidential information. If you are not the intended recipient, please immediately notify us by reply email or by telephone, delete this email and destroy any copies. Thank you.

Mona

unread,
Aug 2, 2013, 5:50:27 PM8/2/13
to google-api...@googlegroups.com
HI, 

Were you able to make this work? 

I am trying something similar which is Creating a Google Event upon Wordpress Jigoshop (shopping cart) new order placement?

Is this possible, I am new to this, would appreciate any advice on this. 

Thanks, 
Mona
Reply all
Reply to author
Forward
0 new messages