【问题标题】:Google Calendar API create event return 403 Forbidden and calendar is public - PHPGoogle Calendar API 创建事件返回 403 Forbidden 并且日历是公开的 - PHP
【发布时间】:2014-04-12 02:48:57
【问题描述】:

我正在尝试使用 Google Calendar Api 3 添加和发送电子邮件事件,但 Google Api 返回 403 Forbidden 并且我的日历设置为公开。 我的代码是:

ini_set('display_errors', 1);
require 'Google/Client.php';
require 'Google/Service/Calendar.php';

session_start();

const CLIENT_ID = '**************.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = '**************@developer.gserviceaccount.com';
const KEY_FILE = '**************-privatekey.p12';

$client = new Google_Client();
$client->setApplicationName("Calendar App");
//$client->setUseObjects(true); //IF USING SERVICE ACCOUNT (YES)

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

$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_Auth_AssertionCredentials(
SERVICE_ACCOUNT_NAME, 'https://www.google.com/calendar/feeds/**************@group.calendar.google.com/private/full/',
$key)
);

$client->setClientId(CLIENT_ID);

$cal = new Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event();
$event->setSummary('App Sum');
$event->setLocation('App Location');

$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2014-05-19T10:30:00.000-05:00');
$event->setStart($start);

$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2014-05-20T11:30:00.000-05:00');
$event->setEnd($end);

$attendeel = new Google_Service_Calendar_EventAttendee();
$attendeel->setEmail('**************@gmail.com');
$attendees = array($attendeel);
$event->attendees = $attendees;

$cal->events->insert('**************@group.calendar.google.com', $event);

http://amazewebs.yitweb.com/#scriptv4 获取代码,有一个类似的代码Edit Google calendar events from Google service account: 403,开发人员说如果没有日历设置则不是代码

他们是否知道是否有其他配置或代码是否真的有问题?

【问题讨论】:

    标签: php api calendar


    【解决方案1】:

    如果您有权访问域管理员帐户,则可以使用该帐户发布日历更新,而无需以管理员身份登录。您可以通过填写 $client 的所有参数来做到这一点:

    setAssertionCredentials(new Google_Auth_AssertionCredentials(
         SERVICE_ACCOUNT_NAME,           
         'https://www.google.com/calendar/feeds/**************@group.calendar.google.com/private/full/',
         $key,
         'notasecret',
         'http://oauth.net/grant_type/jwt/1.0/bearer',
         'your admin account email');
    

    【讨论】:

      【解决方案2】:

      我也一直在玩这个东西。我让列表事件正常工作,但随后切换到添加事件,我得到了这个 401。我发现你必须与 **************@developer.gserviceaccount 共享日历。 com 电子邮件。为此,您可以转到日历 > 我的日历 >(名称)> 共享此日历,然后在与特定人员共享下,添加该 gserviceaccount 电子邮件并设置适当的权限。

      非常感谢postpost

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-09
        • 2016-07-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-23
        相关资源
        最近更新 更多