我有一个Google Apps帐户。我正在尝试操纵此帐户中的用户日历。
我无法做的是创建一个子日历。我已经通读了https://developers.google.com/accounts/docs/OAuth2ServiceAccount,并试图通过“prn”发送。
这是脚本失败的地方;刷新OAuth2令牌时出错,消息:'{“error”:“access_denied”}'。如果我删除了prn,那么一切都“好”。日历只是在开发者电子邮件下创建的。代码:
<?
ini_set('display_errors', 1);
session_start();
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_CalendarService.php';
const CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com';
const MY_EMAIL = 'joe@domain.com';
const KEY_FILE = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx-privatekey.p12';
$client = new Google_Client();
$client->setClientId(CLIENT_ID);
$client->setApplicationName("My App");
$client->setAccessType('offline');
$client->setUseObjects(true);
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
$key = file_get_contents(KEY_FILE);
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
} else {
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/calendar'),
$key,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
MY_EMAIL)
);
}
// even tried setting the email here
$client->setClientId(MY_EMAIL);
$calendar = new Google_Calendar();
$calendar->setSummary('calendarx');
$calendar->setTimeZone('Australia/Brisbane');
$createdCalendar = $cal->calendars->insert($calendar);
?>
非常感谢任何帮助。
答案 0 :(得分:1)
如果域管理员启用了您的应用程序(基于客户端ID)来模拟用户,则prn字段仅适用于托管域。