【问题标题】:Error 400: Invalid prompt for Google Calendar API PHP错误 400:Google 日历 API PHP 的提示无效
【发布时间】:2018-12-03 10:15:29
【问题描述】:

我正在使用 Google 文档中的代码。 Link

我的代码是这样的,

$client = new Google_Client();
$client->setApplicationName('Google Calendar API PHP Quickstart');
$client->setScopes(Google_Service_Calendar::CALENDAR_READONLY);
$client->setAuthConfig('credentials.json');
$client->setAccessType('offline');
$client->setPrompt('select_account consent');

但是当我运行它时,它给出了一个错误。

400. That’s an error.
Error: invalid_request
Invalid parameter value for prompt: Invalid prompt: select_account consent/calendar

请帮忙。
提前致谢。

【问题讨论】:

    标签: php google-api google-calendar-api google-api-php-client


    【解决方案1】:

    如果你查看库的源代码client.php

       /**
       * Set the prompt hint. Valid values are none, consent and select_account.
       * If no value is specified and the user has not previously authorized
       * access, then the user is shown a consent screen.
       * @param $prompt string
       */
      public function setPrompt($prompt)
      {
        $this->config['prompt'] = $prompt;
      }
    

    我不认为你可以同时拥有我认为你应该将其设置为一个或另一个

    $client->setPrompt('consent');
    

    这意味着您正在学习的教程中存在错误。

    我的代码

        $client = new Google_Client();
        $client->setAccessType("offline");        // offline access.  Will result in a refresh token
        $client->setIncludeGrantedScopes(true);   // incremental auth
        $client->setAuthConfig(__DIR__ . '/client_secrets.json');
        $client->addScope(Google_Service_Calendar::CALENDAR_READONLY);
        $client->setRedirectUri(getRedirectUri());  
    

    我的代码Oauth2Authentication.phpoauth2callback.php

    【讨论】:

    • 亲爱的@DalmTo,感谢您的建议。我已经检查了“select_account”和“consent”。但是每个人都会出错。当我使用'select_account'时,它给Invalid parameter value for prompt: Invalid prompt: select_account/calendar当'同意'时,Invalid parameter value for prompt: Invalid prompt: consent/calendar
    • 如果您完全删除该行会发生什么?
    • Invalid parameter value for approval_prompt: 'auto/calendar' is not valid
    • 如您所见,我不使用提示符
    • 我现在收到了Invalid parameter value for include_granted_scopes: Invalid value, must be one of false, true: true/calendar :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-04
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多