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

        <tfoot id='lM1f7'></tfoot>

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

        • <bdo id='lM1f7'></bdo><ul id='lM1f7'></ul>
        <legend id='lM1f7'><style id='lM1f7'><dir id='lM1f7'><q id='lM1f7'></q></dir></style></legend>

        使用服务帐户,getAccessToken() 返回 null

        Using a Service Account, getAccessToken() is returning null(使用服务帐户,getAccessToken() 返回 null)
          • <legend id='beIkz'><style id='beIkz'><dir id='beIkz'><q id='beIkz'></q></dir></style></legend>

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

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

              <tfoot id='beIkz'></tfoot>
                <tbody id='beIkz'></tbody>
                  本文介绍了使用服务帐户,getAccessToken() 返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在运行以下 PHP 代码,使用此处找到的客户端库:https://code.google.com/p/google-api-php-client/.我没有收到任何此代码的错误,但是当我调用 getAccessToken() 时,它返回 null.

                  I am running the following PHP code, using the client libraries found here: https://code.google.com/p/google-api-php-client/. I do not get any errors for any of this code, but when I call getAccessToken(), it returns null.

                  我已允许在我的个人日历上访问此服务帐户,并已通过 API 控制台授予对项目的完全访问权限.

                  I have allowed access to this service account on my personal calendar, and have granted full access to the project via the API Console.

                  有什么想法吗?

                  require_once 'google-api-php-client/src/Google_Client.php';
                  
                  const CLIENT_ID = 'blahblahblah';
                  const SERVICE_ACCOUNT_NAME = 'blahblahblah@developer.gserviceaccount.com';
                  const KEY_FILE = 'path/to/privatekey.p12';
                  
                  $google_client = new Google_Client(); // created only to initialized static dependencies
                  $client = new Google_OAuth2(); // you really just need Google_OAuth2
                  
                  $key = file_get_contents(KEY_FILE);  
                  
                  $client->setAssertionCredentials(
                      new Google_AssertionCredentials(
                          SERVICE_ACCOUNT_NAME,
                          array('https://www.googleapis.com/auth/calendar'),
                          $key
                      )
                  );
                  
                  var_dump($client->getAccessToken());
                  

                  推荐答案

                  出于某种原因,这似乎有效:

                  For some reason, this seemed to work:

                  require_once 'google-api-php-client/src/Google_Client.php';
                  
                  const CLIENT_ID = 'blahblahblah';
                  const SERVICE_ACCOUNT_NAME = 'blahblahblah@developer.gserviceaccount.com';
                  const KEY_FILE = 'path/to/privatekey.p12';
                  const CALENDAR_SCOPE = "https://www.googleapis.com/auth/calendar";
                  
                  $key = file_get_contents(KEY_FILE);
                  $auth = new Google_AssertionCredentials(
                      SERVICE_ACCOUNT_NAME,
                      array(CALENDAR_SCOPE),
                      $key
                  );
                  
                  $client = new Google_Client();
                  $client->setScopes(array(CALENDAR_SCOPE));
                  $client->setAssertionCredentials($auth);
                  $client->getAuth()->refreshTokenWithAssertion();
                  $accessToken = $client->getAccessToken();
                  
                  $client->setClientId(CLIENT_ID);
                  

                  如果有人可以解释为什么这是有效的,请编辑此答案或评论!

                  If someone can explain why this worked, please edit this answer or comment!

                  这篇关于使用服务帐户,getAccessToken() 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)
                    <tbody id='O1HK3'></tbody>
                  <legend id='O1HK3'><style id='O1HK3'><dir id='O1HK3'><q id='O1HK3'></q></dir></style></legend>
                      1. <i id='O1HK3'><tr id='O1HK3'><dt id='O1HK3'><q id='O1HK3'><span id='O1HK3'><b id='O1HK3'><form id='O1HK3'><ins id='O1HK3'></ins><ul id='O1HK3'></ul><sub id='O1HK3'></sub></form><legend id='O1HK3'></legend><bdo id='O1HK3'><pre id='O1HK3'><center id='O1HK3'></center></pre></bdo></b><th id='O1HK3'></th></span></q></dt></tr></i><div id='O1HK3'><tfoot id='O1HK3'></tfoot><dl id='O1HK3'><fieldset id='O1HK3'></fieldset></dl></div>

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

                        <tfoot id='O1HK3'></tfoot>

                          <bdo id='O1HK3'></bdo><ul id='O1HK3'></ul>