PHP Google API - 缺少范围

时间:2013-04-17 16:32:31

标签: php google-api oauth-2.0 google-calendar-api google-oauth

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

1 个答案:

答案 0 :(得分:7)

在设置了developerKey

之后错过了这一行
$cal = new \Google_CalendarService($client);

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