我使用的是基于Google的日历示例应用程序,它工作得很好。
$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Starter Application");
$client->setClientId('myclientid.apps.googleusercontent.com');
$client->setClientSecret('mysecret');
$client->setRedirectUri('http://localhost/admin/index.php?m=1&e=calendar');
$client->setDeveloperKey('mykey');
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if (!$client->getAccessToken()) {
$authUrl = $client->createAuthUrl();
header('Location: ' . $authUrl);
}
但是我得到:
Error: invalid_request
Missing required parameter: scope
在我设置了developerKey
之后缺少了这一行$cal = new Google_CalendarService($client);
我猜从客户端获取日历服务的行为设置了作用域。很合理。