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

  2. <i id='EDtqI'><tr id='EDtqI'><dt id='EDtqI'><q id='EDtqI'><span id='EDtqI'><b id='EDtqI'><form id='EDtqI'><ins id='EDtqI'></ins><ul id='EDtqI'></ul><sub id='EDtqI'></sub></form><legend id='EDtqI'></legend><bdo id='EDtqI'><pre id='EDtqI'><center id='EDtqI'></center></pre></bdo></b><th id='EDtqI'></th></span></q></dt></tr></i><div id='EDtqI'><tfoot id='EDtqI'></tfoot><dl id='EDtqI'><fieldset id='EDtqI'></fieldset></dl></div>
      <bdo id='EDtqI'></bdo><ul id='EDtqI'></ul>
  3. <legend id='EDtqI'><style id='EDtqI'><dir id='EDtqI'><q id='EDtqI'></q></dir></style></legend>
      <tfoot id='EDtqI'></tfoot>

      Google-api-php 刷新令牌返回 invalid_grant

      Google-api-php Refresh Token returns invalid_grant(Google-api-php 刷新令牌返回 invalid_grant)

        1. <tfoot id='WsDzS'></tfoot>

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

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

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

              • 本文介绍了Google-api-php 刷新令牌返回 invalid_grant的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我几乎搜索了谷歌第一页的所有结果.但似乎无法找到答案.我正在使用 Google API 的 refresh_token 并接收:

                I've nearly searched every result of the first page of google for this. But can't seem to find the answer. I'm working with a refresh_token by Google's API and receiving:

                Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }
                

                我在做什么.首先:我正在创建并存储与 google api 的持久连接:

                What i'm doing. First: i'm creating and storing a persistant connection to the google api:

                $client = new Google_Client();
                $client->setClientId('xxxxxx-s73q0pa41aq3i2kcpatmpas6e6kkp99h.apps.googleusercontent.com');
                $client->setClientSecret('xxxxxxxxxxxx');
                $client->setRedirectUri('http://xxxxxxxx/generaterefreshtoken.php');
                $client->setScopes(array('https://www.googleapis.com/auth/drive'));
                $client->setAccessType('offline');
                
                
                if (isset($_GET['code'])) {
                  $client->authenticate();
                  $_SESSION['token'] = $client->getAccessToken();
                  $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
                  header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
                }
                
                if (isset($_SESSION['token'])) {
                 $client->setAccessToken($_SESSION['token']);
                }
                
                if (isset($_REQUEST['logout'])) {
                  unset($_SESSION['token']);
                  $client->revokeToken();
                }
                
                if ($client->getAccessToken()) {
                
                    $jsonarray = json_decode($client->getAccessToken());
                    $arrGoogleAuth['access_token']=$jsonarray->access_token;
                    $arrGoogleAuth['refresh_token']=$jsonarray->refresh_token;
                    //filewrite
                
                    $myFile = "refreshtoken.conf";
                    $fh = fopen($myFile, 'w') or die("can't open file");
                    fwrite($fh, $client->getAccessToken());
                    fclose($fh);
                
                
                    /*
                
                    die();
                
                    $service = new Google_DriveService($client);
                    $file = new Google_DriveFile();
                    $file->setTitle('My document.txt');
                    $file->setDescription('A test document');
                    $file->setMimeType('text/plain');
                
                    $data = file_get_contents('document.txt');
                
                    $createdFile = $service->files->insert($file, array(
                          'data' => $data,
                          'mimeType' => 'text/plain',
                        ));
                
                    print_r($createdFile);
                */
                
                
                
                  // The access token may have been updated lazily.
                  $_SESSION['token'] = $client->getAccessToken();
                } else {
                  $auth = $client->createAuthUrl();
                  header("Location: $auth");
                }
                

                所以基本上一切都在运行并且令牌被存储在一个文本文件中:

                So basicly everything runs and the token gets stored in a textfile:

                {
                "access_token":"xxxxxxxxxxxxxxxN4U0ys2wy5monxs0Xh5fu5ayKL0OIENo-d1sN6g3YA",
                "token_type":"Bearer",
                "expires_in":3600,
                "refresh_token":"xxxxxxxxxxxxDON-l90BNUcJgnkfZWDfg",
                "created":1358120143
                }
                

                当我尝试使用以下代码进行身份验证时:

                When i'm trying to auth using the following code:

                $client = new Google_Client();
                $client->setClientId($googleDriveConfig['clientid']);
                $client->setClientSecret($googleDriveConfig['clientsecret']);
                $client->setRedirectUri(curPageURL);
                $client->setScopes(array('https://www.googleapis.com/auth/drive'));
                $client->refreshToken(file_get_contents('../_config/refreshtoken.conf'));
                $client->authenticate();
                

                我收到以下错误:刷新 OAuth2 令牌时出错,消息:'{ "error" : "invalid_grant" }

                I'm getting the following error: Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }

                推荐答案

                在 Authenticate 之前,必须有类似的东西:

                Before Authenticate, there must be something like:

                $client->grantType("refresh_token")
                

                这篇关于Google-api-php 刷新令牌返回 invalid_grant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <bdo id='gybAi'></bdo><ul id='gybAi'></ul>
                  • <i id='gybAi'><tr id='gybAi'><dt id='gybAi'><q id='gybAi'><span id='gybAi'><b id='gybAi'><form id='gybAi'><ins id='gybAi'></ins><ul id='gybAi'></ul><sub id='gybAi'></sub></form><legend id='gybAi'></legend><bdo id='gybAi'><pre id='gybAi'><center id='gybAi'></center></pre></bdo></b><th id='gybAi'></th></span></q></dt></tr></i><div id='gybAi'><tfoot id='gybAi'></tfoot><dl id='gybAi'><fieldset id='gybAi'></fieldset></dl></div>
                      <tbody id='gybAi'></tbody>
                    <tfoot id='gybAi'></tfoot>

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

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