我正在尝试使用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,开发人员说如果没有日历设置则代码不是代码
他们是否知道是否存在其他配置或代码是否确实存在问题?
答案 0 :(得分: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');
答案 1 :(得分:0)