简体   繁体   English

从脚本中将事件插入谷歌日历

[英]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. 几个星期前,我构建了一个使用标准Oauth 2.0协议的日历,但这依赖于用户浏览器存储的会话。 I have one calendar that I want to pass events to from an application I am writing with a basic PHP framework. 我有一个日历,我想从我用基本PHP框架编写的应用程序传递事件。 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. 非常感谢。

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: 尝试Zend_Gdata_Calendar使用此库,您可以从谷歌日历插入或获取任何用户的事件(显然具有正确的用户名和密码),并与您自己的日历集成或显示它。这里有一个简短的例子:

    $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
    $client = Zend_Gdata_ClientLogin::getHttpClient('gmail@user.com',    '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... 使用此功能,您可以使用邮件和密码从任何用户的日历表格中添加,更新,编辑或删除事件...

Use OAuth 2 and the Authorization Code flow (web server flow), with offline enabled. 启用离线时,使用OAuth 2和授权代码流(Web服务器流)。 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. 存储刷新令牌(无限期地持续到用户撤销为止),即使用户当前未登录,您也可以将事件上传到Google日历。

More info: https://developers.google.com/accounts/docs/OAuth2WebServer#offline 更多信息: https//developers.google.com/accounts/docs/OAuth2WebServer#offline

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM