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

    <tfoot id='gl70X'></tfoot>

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

    <legend id='gl70X'><style id='gl70X'><dir id='gl70X'><q id='gl70X'></q></dir></style></legend>
      <bdo id='gl70X'></bdo><ul id='gl70X'></ul>
    1. 使用服务帐户访问 Google 日历事件:{ "error";:“访问被拒绝"}.没有谷歌

      Access Google calendar events from with service account: { quot;errorquot; : quot;access_deniedquot; }. No google apps(使用服务帐户访问 Google 日历事件:{ error;:“访问被拒绝}.没有谷歌应用)
    2. <small id='EBXfa'></small><noframes id='EBXfa'>

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

                本文介绍了使用服务帐户访问 Google 日历事件:{ "error";:“访问被拒绝"}.没有谷歌应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想使用服务帐户访问谷歌日历.这是我的代码: 被 Google API 控制台上的正确值替换.

                I would like to access google calendar using Service account. This is my code : <NUMBER> is replace by the correct value take on Google API Console.

                <?php
                
                require_once 'googleapi/Google_Client.php';
                require_once 'googleapi/contrib/Google_CalendarService.php';
                
                const CLIENT_ID = '<NUMBER>.apps.googleusercontent.com';
                const SERVICE_ACCOUNT_NAME  = '<NUMBER>@developer.gserviceaccount.com';
                const MY_EMAIL  = '<MY NAME>@gmail.com';
                const KEY_FILE = 'privatekey.p12';
                
                $client = new Google_Client();
                $client->setClientId(CLIENT_ID);
                $client->setApplicationName("<APP NAME>");
                
                $key = file_get_contents(KEY_FILE);
                $client->setAssertionCredentials(new Google_AssertionCredentials(
                    SERVICE_ACCOUNT_NAME,
                    array('https://www.googleapis.com/auth/calendar'),
                    $key,
                    'notasecret',
                    'http://oauth.net/grant_type/jwt/1.0/bearer',
                    MY_EMAIL)
                );
                
                $cal = new Google_CalendarService($client);
                $calList = $cal->calendarList->listCalendarList();
                
                print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";
                

                当我执行我的代码时,我收到:

                When I execute my code, I receive:

                致命错误:带有消息的未捕获异常Google_AuthException"'刷新 OAuth2 令牌时出错,消息:'{错误":"access_denied" }'' 在/home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/googleapi/auth/Google_OAuth2.php:279堆栈跟踪:#0/home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/googleapi/auth/Google_OAuth2.php(256):Google_OAuth2->refreshTokenRequest(Array) #1/home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/googleapi/auth/Google_OAuth2.php(209):Google_OAuth2->refreshTokenWithAssertion() #2/home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/googleapi/service/Google_ServiceResource.php(166):Google_OAuth2->sign(Object(Google_HttpRequest)) #3/home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/googleapi/contrib/Google_CalendarService.php(154):Google_ServiceResource->__call('list', Array) #4/home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/testService.php(32):Google_CalendarListServiceResource->listCalendarList() #5 {main}扔进去/home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/googleapi/auth/Google_OAuth2.php在线 279

                Fatal error: Uncaught exception 'Google_AuthException' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "access_denied" }'' in /home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/googleapi/auth/Google_OAuth2.php:279 Stack trace: #0 /home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/googleapi/auth/Google_OAuth2.php(256): Google_OAuth2->refreshTokenRequest(Array) #1 /home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/googleapi/auth/Google_OAuth2.php(209): Google_OAuth2->refreshTokenWithAssertion() #2 /home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/googleapi/service/Google_ServiceResource.php(166): Google_OAuth2->sign(Object(Google_HttpRequest)) #3 /home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/googleapi/contrib/Google_CalendarService.php(154): Google_ServiceResource->__call('list', Array) #4 /home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/testService.php(32): Google_CalendarListServiceResource->listCalendarList() #5 {main} thrown in /home/www/65683f67e3f0d94b14bba3c945014cda/web/intranet/googleapi/auth/Google_OAuth2.php on line 279

                如果我使用以下代码更改代码:

                If I change my code with :

                $client->setAssertionCredentials(new Google_AssertionCredentials(
                SERVICE_ACCOUNT_NAME,
                array('https://www.googleapis.com/auth/calendar'),
                $key));
                

                我收到:

                (403) 访问权限未配置

                (403) Access Not Configured

                这里出了什么问题?

                推荐答案

                我有解决方案.首先是好的代码是最后的:

                I have the solution. First the good code is the last:

                $client->setAssertionCredentials(new Google_AssertionCredentials(
                      SERVICE_ACCOUNT_NAME,
                      array('https://www.googleapis.com/auth/calendar'),
                      $key));
                

                问题不是代码,而是我的谷歌帐户,我在谷歌API控制台中提到了一个Referer.擦除字段后,代码有效.

                The problem is not the code, but my google account, I have mentioned a Referer in Google API Console. After erasing the field, the code works.

                仅供参考,如果您想访问共享日历,请不要忘记与您的 XXXXXX@developer.gserviceaccount.com(您的 SERVICE_ACCOUNT_NAME)共享您的日历.

                For information purposes, if you would like to access shared calendars, do not forget to share your calendar with your XXXXXX@developer.gserviceaccount.com (your SERVICE_ACCOUNT_NAME).

                有关更多信息,请参阅:

                For more information, see:

                https://groups.google.com/forum/?fromgroups=#!topic/google-ajax-search-api/kaKYuUstwB0/discussion

                这篇关于使用服务帐户访问 Google 日历事件:{ "error";:“访问被拒绝"}.没有谷歌应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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 的问题)
                <tfoot id='NEHuu'></tfoot>
                • <bdo id='NEHuu'></bdo><ul id='NEHuu'></ul>

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

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

                            <tbody id='NEHuu'></tbody>