使用php将事件添加到谷歌日历,而不是由多个用户登录

时间:2012-11-23 12:13:54

标签: php google-calendar-api

我拥有谷歌API控制台生成的所有客户端ID,客户端密码,API密钥,令牌授权代码等。我也激活了日历服务。我组建了一个可以编辑一个日历的2人团队。现在,我希望以这样的方式编写代码,即他们都可以将事件添加到该日历而无需登录到他们的帐户。要求登录才能查看日历,显然无法添加事件。我被引用了很多教程,比如oauth 2.0等,但后来没有得到确切的想法。会有可能吗?

<?php
require_once 'google-api-client/src/Google_Client.php';
require_once 'google-api-client/src/contrib/Google_CalendarService.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Starter Application");
// Visit code.google.com/apis/console?api=calendar to generate your
// client id, client secret, and to register your redirect uri.
$client->setClientId('client id');
$client->setClientSecret('cliet secret');
$client->setRedirectUri('my calendar url generated after clicking to HTML button');
$calendarListEntry = new Google_CalendarListEntry("My calendar entry");
$calendarListEntry->setId("ajoshi.kraff@gmail.com");
$createdCalendarListEntry = $cal->calendarList->insert($calendarListEntry);
echo $createdCalendarListEntry->getSummary();

1 个答案:

答案 0 :(得分:0)

这种情况描述为in google docs

用户提供正确的凭据后,Google oauth服务器会将他重定向到您的服务并提供访问令牌(您可以立即使用它来签署您的请求)和刷新令牌< / strong>您可以使用它来获取新的访问令牌。您必须获得新的访问权限,因为它们已过期。刷新令牌可让您在没有用户存在的情况下获得新的访问令牌 - 例如,在后台服务中。因此,您应该将刷新令牌存储在数据库中(或任何您想要的地方)。

查看此文档页面: https://developers.google.com/accounts/docs/OAuth2WebServer