通过Google服务帐号修改Google日历活动:403 [英] Edit Google calendar events from Google service account: 403

查看:100
本文介绍了通过Google服务帐号修改Google日历活动:403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从服务帐户的Google日历中创建新活动。
我可以正确访问并列出所有日历列表。
但是当我想创建一个新的事件时,响应是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(新的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 pelmatí!');
$ 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)禁止

任何想法?也许其他的范围,或允许编辑事件(我不知道我可以在哪里配置这个,我已经搜索过它,承诺)



当然,我的日历是公共日历。



欢迎任何帮助:)

谢谢!

解决方案

我解决了这个问题,并且问题不是代码,它可以正常工作。

问题是共享我的日历。一些我不知道的事情。



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



这可能是一个问题如果这是一个商业帐户,那么你将不得不联系帐户管理员。



这里显示的代码正常工作,所以我希望它可以帮助某人,只记得你必须使用475版本的Google Api Client。



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


I want to create new event at google calendar from Service Account. I can access correctly and print a list all my calendars. But when I want to create a new event the response is 403 Forbidden.

My code:

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);

And server response:

(403) Forbidden

Any ideas? Maybe other scope, or allow edit events (I dont know where I can configure this and I have searched it, promise)

Of course, my calendar is a public calendar.

Any help will be welcome :)

Thanks!

解决方案

I solved it, and the issue was not code, It works fine.

The problem was sharing my calendar. Something that I don't knew.

To allow edit your calendar events from service account, do not have enough with all steps you do in the Google Api Console, you have to give permission from your calendar configuration (Calendar configuration -> Share this calendar) to the email account specified into Google Api Console (email adress).

This can be a problem if it's a business account, then you will have to contact the account administrator.

The code shown here works correctly, so I hope it helps someone, just remember that you must use 475 version of the Google Api Client.

You can find at this link: http://google-api-php-client.googlecode.com/svn/trunk/src/

这篇关于通过Google服务帐号修改Google日历活动:403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆