我正在使用以下内容,基于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
答案 0 :(得分:7)
在设置了developerKey
之后错过了这一行$cal = new \Google_CalendarService($client);
我想从客户端获取日历服务的行为会设置范围。很合理。