2

我正在使用以下内容,基于 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
4

1 回答 1

7

设置 developerKey 后缺少此行

$cal = new \Google_CalendarService($client);

我猜想从客户端获取日历服务的行为设定了范围。很合理。

于 2013-04-17T17:49:34.050 回答