Rivers
Rivers

Reputation: 2102

Inserting Events to google calendar from a script

Anyone know the proper way to authenticate and publish directly to a calendar without relying on a currently logged in user? Several weeks ago I built a calendar that used the standard Oauth 2.0 protocol but this relied sessions stored by a user's we browser. I have one calendar that I want to pass events to from an application I am writing with a basic PHP framework. I'm more concerned with what are the best practices that others are using. Your answer could be simply, don't do it. Thanks alot.

Upvotes: 0

Views: 701

Answers (2)

Ryan Boyd
Ryan Boyd

Reputation: 3018

Use OAuth 2 and the Authorization Code flow (web server flow), with offline enabled. Store the refresh tokens (which last indefinitely until the user has revoked), and you'll be able to upload events to Google Calendar even when the user isn't currently logged in.

More info: https://developers.google.com/accounts/docs/OAuth2WebServer#offline

Upvotes: 1

ALEX ORTIZ
ALEX ORTIZ

Reputation: 189

try Zend_Gdata_Calendar with this library you are able to insert or get events from any user(with the right username and password obviously) from google calendar and integrate with your own calendar or display it..here a short example:

    $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
    $client = Zend_Gdata_ClientLogin::getHttpClient('[email protected]',    'gmailpassword', $service);
    $service = new Zend_Gdata_Calendar($client);



    $query = $service->newEventQuery();
    $query->setUser('default');
    $query->setVisibility('private');


    try {
         $eventFeed = $service->getCalendarEventFeed($query);
    } catch (Zend_Gdata_App_Exception $e) {
        echo "Error: " . $e->getMessage();
    }


    echo "<ul>";
    foreach ($eventFeed as $event) {
     echo "<li>" . $event->title . " (Event ID: " . $event->id . ")</li>";

    }
    echo "</ul>";



    $eventURL = "http://www.google.com/calendar/feeds/default/private/full/Dir0FthEpUbl1cGma1lCalendAr";

    try {
        $event = $service->getCalendarEventEntry($eventURL);

        echo 'Evento: ' . $event->getTitle() .'<br>';
        echo 'detalles: ' . $event->getContent().'<br>';
        foreach ($event->getWhen() as $dato)
        {
            echo 'inicia: ' . substr($dato->startTime, 0,-19) . ' a las: ' . substr($dato->startTime, 11,-10) .'<br>';
            echo 'termina: ' .substr($dato->endTime,0,-19) . ' a las: ' . substr($dato->endTime,11,-10) .'<br>';

        }  



    } catch (Zend_Gdata_App_Exception $e) {
        echo "Error: " . $e->getMessage();
    }

with this you can add, update, edit or delete events from calendar form any user with mail and password...

Upvotes: 1

Related Questions