• <tfoot id='pBm13'></tfoot>
        <bdo id='pBm13'></bdo><ul id='pBm13'></ul>

    1. <legend id='pBm13'><style id='pBm13'><dir id='pBm13'><q id='pBm13'></q></dir></style></legend>

      <i id='pBm13'><tr id='pBm13'><dt id='pBm13'><q id='pBm13'><span id='pBm13'><b id='pBm13'><form id='pBm13'><ins id='pBm13'></ins><ul id='pBm13'></ul><sub id='pBm13'></sub></form><legend id='pBm13'></legend><bdo id='pBm13'><pre id='pBm13'><center id='pBm13'></center></pre></bdo></b><th id='pBm13'></th></span></q></dt></tr></i><div id='pBm13'><tfoot id='pBm13'></tfoot><dl id='pBm13'><fieldset id='pBm13'></fieldset></dl></div>

      1. <small id='pBm13'></small><noframes id='pBm13'>

        谷歌身份验证:OAuth2 不断返回“invalid_grant"

        时间:2023-10-02

        <small id='zgRZo'></small><noframes id='zgRZo'>

        <legend id='zgRZo'><style id='zgRZo'><dir id='zgRZo'><q id='zgRZo'></q></dir></style></legend>

        1. <tfoot id='zgRZo'></tfoot>
              <bdo id='zgRZo'></bdo><ul id='zgRZo'></ul>
              <i id='zgRZo'><tr id='zgRZo'><dt id='zgRZo'><q id='zgRZo'><span id='zgRZo'><b id='zgRZo'><form id='zgRZo'><ins id='zgRZo'></ins><ul id='zgRZo'></ul><sub id='zgRZo'></sub></form><legend id='zgRZo'></legend><bdo id='zgRZo'><pre id='zgRZo'><center id='zgRZo'></center></pre></bdo></b><th id='zgRZo'></th></span></q></dt></tr></i><div id='zgRZo'><tfoot id='zgRZo'></tfoot><dl id='zgRZo'><fieldset id='zgRZo'></fieldset></dl></div>
                  <tbody id='zgRZo'></tbody>

                • 本文介绍了谷歌身份验证:OAuth2 不断返回“invalid_grant"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我开始在我的新应用程序上配置谷歌日历.我几乎制作了谷歌开发者展示的身份验证代码的精确副本(https://developers.google.com/google-apps/calendar/instantiate ),但我不断收到以下错误:

                  I started to configure google calendar on my new application. I almost made an exact copy of the authentication code displayed at google developers ( https://developers.google.com/google-apps/calendar/instantiate ), but i keep getting the following error:

                  获取 OAuth2 访问令牌时出错,消息:'invalid_grant'

                  Error fetching OAuth2 access token, message: 'invalid_grant'

                  我目前使用 Fork-CMS ( http://www.fork-cms.com),一个年轻的轻量级 CMS.我正确配置了 google-api-php-client 的 config.php 文件.(client-id, client-secret, redirect-uri, development key,...) 并且在 google api 的控制台上正确设置了重定向 uri.我的代码如下所示:

                  I'm currently using Fork-CMS ( http://www.fork-cms.com ), a young lightweigth CMS. I correctly configured the config.php file of the google-api-php-client. (client-id, client-secret, redirect-uri, development key,...) and the redirect uri is correctly set on the google api's console. My code looks as follows:

                  <?php
                  
                  /**
                  * This is a widget with a calendar implementation.
                  *
                  * @package       frontend
                  * @subpackage    events
                  *
                  * @author        Michiel Vlaminck <michielvlaminck@gmail.com>
                  */
                  class FrontendEventsWidgetCalendar extends FrontendBaseWidget
                  {
                  
                      private $events = array();
                      private $authUrl = array();
                  
                      /**
                      * Execute the extra
                      *
                      * @return    void
                      */
                      public function execute()
                      {      
                          // call parent
                          parent::execute();
                  
                          // load template
                          $this->loadTemplate();
                  
                          // get data
                          $this->getData();
                  
                          // parse
                          $this->parse();
                      }
                  
                  
                      /**
                      * Get the data from Google Calendar
                      * This method is only executed if the template isn't cached
                      *
                      * @return    void
                      */
                      private function getData()
                      {
                          require_once PATH_LIBRARY . '/external/google-api-php-client/src/apiClient.php';
                          require_once PATH_LIBRARY . '/external/google-api-php-client/src/contrib/apiCalendarService.php';
                  
                          $client = new apiClient();
                  
                          $service = new apiCalendarService($client);
                  
                          if (isset($_SESSION['oauth_access_token'])) {
                              $client->setAccessToken($_SESSION['oauth_access_token']);
                          } else {
                              $token = $client->authenticate();
                              $_SESSION['oauth_access_token'] = $token;
                          }
                  
                          if ($client->getAccessToken()) {
                  
                              $calId = FrontendEventsModel::getCalendarId((int) $this->data['id']);
                              $calId = $calId[0]['calendar_id'];
                  
                              $events = $service->events->listEvents($calId);
                              $this->events = $events['items'];
                  
                              $_SESSION['oauth_access_token'] = $client->getAccessToken();
                  
                          } else {
                              $this->authUrl = $client->createAuthUrl();
                          }
                      }
                  
                  
                      /**
                      * Parse
                      *
                      * @return    void
                      */
                      private function parse()
                      {
                          $this->tpl->assign('events', $this->events);
                          $this->tpl->assign('authUrl', $this->authUrl);
                      }
                  }
                  
                  ?>
                  

                  当我第一次打开这个小部件页面时,我被引导到谷歌来验证应用程序.当我同意时,我被重定向到我的应用程序,这就是我得到的点:

                  When I open this widget-page for the first time, I get directed to google to authenticate the application. When I agree, I get redirected to my application and that's the point where I'm getting:

                  apiAuthException » Main
                  
                  Message Error fetching OAuth2 access token, message: 'invalid_grant'
                  File    C:wampwwwOfficevibeslibrary/externalgoogle-api-php-clientsrcauthapiOAuth2.php
                  Line    105
                  Date    Thu, 05 Apr 2012 08:34:47 +0000
                  URL http://localhost/calendar?code=4/YPUpFklKvhEeTcMm4moRth3x49oe
                  Referring URL   (Unknown)
                  Request Method  GET
                  User-agent  Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.142 Safari/535.19
                  

                  推荐答案

                  您应该重复使用在第一次成功验证后获得的访问令牌.如果您之前的令牌尚未过期,您将收到 invalid_grant 错误.将其缓存在某处,以便您可以重复使用.

                  You should reuse the access token you get after the first successful authentication. You will get an invalid_grant error if your previous token has not expired yet. Cache it somewhere so you can reuse it.

                  这篇关于谷歌身份验证:OAuth2 不断返回“invalid_grant"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:服务应用程序和 Google Analytics API V3:服务器到服务 下一篇:如何使用带有自定义用户名列的 Laravel Passport

                  相关文章

                  最新文章

                • <legend id='fMhuk'><style id='fMhuk'><dir id='fMhuk'><q id='fMhuk'></q></dir></style></legend>

                    • <bdo id='fMhuk'></bdo><ul id='fMhuk'></ul>

                      <small id='fMhuk'></small><noframes id='fMhuk'>

                      <tfoot id='fMhuk'></tfoot>
                      <i id='fMhuk'><tr id='fMhuk'><dt id='fMhuk'><q id='fMhuk'><span id='fMhuk'><b id='fMhuk'><form id='fMhuk'><ins id='fMhuk'></ins><ul id='fMhuk'></ul><sub id='fMhuk'></sub></form><legend id='fMhuk'></legend><bdo id='fMhuk'><pre id='fMhuk'><center id='fMhuk'></center></pre></bdo></b><th id='fMhuk'></th></span></q></dt></tr></i><div id='fMhuk'><tfoot id='fMhuk'></tfoot><dl id='fMhuk'><fieldset id='fMhuk'></fieldset></dl></div>