首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Google Calendar API创建事件返回403禁止,日历是公共的- PHP

Google Calendar API创建事件返回403禁止,日历是公共的- PHP
EN

Stack Overflow用户
提问于 2014-04-12 10:48:57
回答 2查看 3.6K关注 0票数 1

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

代码语言:javascript
运行
复制
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,如果没有日历设置,开发人员会说这不是代码

他们是否知道是否存在其他配置,或者代码是否真的是问题所在?

EN

回答 2

Stack Overflow用户

发布于 2014-11-19 04:26:30

如果您拥有域管理员帐户的访问权限,则可以以该帐户的身份发布日历更新,而无需以管理员身份登录。您可以通过填写$client的所有参数来完成此操作

代码语言:javascript
运行
复制
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');
票数 1
EN

Stack Overflow用户

发布于 2014-04-26 04:58:27

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

非常感谢这个post和这个post

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23025498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档