gpt4 book ai didi

php - 从 Google 服务帐户 : 403 编辑 Google 日历事件

转载 作者:可可西里 更新时间:2023-11-01 13:10:24 26 4
gpt4 key购买 nike

我想通过服务帐户在谷歌日历中创建新事件。我可以正确访问并打印我所有日历的列表。但是当我想创建一个新事件时,响应是 403 Forbidden。

我的代码:

require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_CalendarService.php';

session_start();

const CLIENT_ID = 'XXXXXXXXXX.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = 'XXXXXXXXXXXX@developer.gserviceaccount.com';

const KEY_FILE = 'google_src/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-privatekey.p12';

$client = new Google_Client();
$client->setApplicationName("APP_NAME");

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

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

$client->setClientId(CLIENT_ID);
$cal = new Google_CalendarService($client);
$event = new Google_Event();
$event->setSummary('Bon dia pel matí!');
$event->setLocation('Somewhere');
$start = new Google_EventDateTime();
$start->setDateTime('2012-08-06T10:00:00.000-07:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2012-09-06T10:25:00.000-07:00');
$event->setEnd($end);

$createdEvent = $cal->events->insert(CALENDAR_NAME, $event);

和服务器响应:

(403) Forbidden

有什么想法吗?也许其他范围,或允许编辑事件(我不知道我可以在哪里配置它,我已经搜索过了,保证)

当然,我的日历是公共(public)日历。

欢迎任何帮助:)

谢谢!

最佳答案

我解决了,问题不是代码,它工作正常。

问题在于共享我的日历。我不知道的事情。

要允许从服务帐户编辑您的日历事件,您在 Google Api 控制台中执行的所有步骤还不够,您必须从您的日历配置(日历配置 -> 共享此日历)向电子邮件帐户授予权限指定到 Google Api 控制台(电子邮件地址)。

如果是企业帐户,这可能是个问题,然后您必须联系帐户管理员。

这里显示的代码工作正常,所以我希望它能帮助别人,请记住你必须使用 475 版本的 Google Api 客户端。

您可以在此链接中找到: http://google-api-php-client.googlecode.com/svn/trunk/src/

关于php - 从 Google 服务帐户 : 403 编辑 Google 日历事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11863022/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com