- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用服务帐户访问谷歌日历。这是我的代码: <NUMBER>
被 Google API 控制台上的正确值所取代。
<?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>";
当我执行我的代码时,我收到:
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
如果我更改我的代码:
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/calendar'),
$key));
我收到:
(403) Access Not Configured
这里出了什么问题?
最佳答案
我有解决方案。首先好的代码是最后的:
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/calendar'),
$key));
问题不在于代码,而在于我的谷歌帐户,我在 Google API 控制台中提到了一个 Referer。删除该字段后,代码可以正常工作。
出于信息目的,如果您想访问共享日历,请不要忘记与您的 XXXXXX@developer.gserviceaccount.com(您的 SERVICE_ACCOUNT_NAME)共享您的日历。
有关详细信息,请参阅:
https://groups.google.com/forum/?fromgroups=#!topic/google-ajax-search-api/kaKYuUstwB0/discussion
关于php - 使用服务帐户 : { "error" : "access_denied" }. 访问 Google 日历事件 没有谷歌应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13111396/
通过使用以下curl命令,我可以访问 token 并获得以下响应curl 用户名:密码@机器名:11002/appName/oauth/token -d grant_type=密码 -d 用户名=lo
我目前将应用程序转换为使用 CreateProcessW() 而不是 Runtime.exec(),因为我需要它提供的信息。但是,对 CreateProcessW() 的任何调用都会失败,并显示错误代
我目前使用 sphinxql 并在我的 $query 上使用 mysql_real_escape_string 但由于没有数据库连接...我的访问被拒绝。我在寻找替代品: $query = $_GET
我有一个 java vertx 服务器和一个 JavaScript 客户端。我想在两次下创建一个事件总线,但 vertx 响应:连接时收到错误:access_denied Javascript 代码:
我正在我的 asp.net webapi 2 中实现 oAuth 流。我必须获得用户的许可才能访问他们的 google 分析数据。为此,我在向 google oAuth2.0 流程发送身份验证请求时添
此程序枚举所有句柄并获取它们的名称。 对于 pID 4,OpenProcess 使用 SeDebugPrivilege 获得错误 5。 UAC 关闭。从管理员运行。 启用 SeDebugPrivile
我使用 rails 5.0 康康 1.6.10 设计 4.2.0 事件管理员 我经常在 newrelic 中遇到此错误: NoMethodError: undefined method `access
我正在尝试使用 Java Google Calendar api 连接到日历。 java 应用程序使用服务帐户。 我有以下代码: java.io.File licenseFile = new j
我正在尝试将 google drive photo 下载到我的本地驱动器。我认为这应该是一项简单的任务,但它实际上具有挑战性,尤其是这是我第一次尝试使用 google API。 按照这个有用的 You
我按照下面的这篇文章进行操作,但在“测试用户流程”部分中收到了以下错误: https://learn.microsoft.com/en-gb/azure/active-directory-b2c/co
我按照下面的这篇文章进行操作,但在“测试用户流程”部分中收到了以下错误: https://learn.microsoft.com/en-gb/azure/active-directory-b2c/co
我正在尝试对 WebApi 实现 OAuth 身份验证,我已经使用以下方法创建了 Controller (直接来自示例): [OverrideAuthentication] [Host
使用 spring boot Rest 模板调用 GET 调用时出现访问被拒绝错误的 sslhandshake 异常。 我正在开发一个 Java 客户端以从普罗米修斯服务器获取指标。创建一个带有基本身
我想使用服务帐户访问谷歌日历。这是我的代码: 被 Google API 控制台上的正确值所取代。 .apps.googleusercontent.com'; const SERVICE_ACCOUNT
我已经设置了我的 Google OAuth 我已将代码添加到 Startup.Auth.cs app.UseGoogleAuthentication(new GoogleOAuth2Authenti
我是 Playframework 的新手。我的intellij无法导入sbt项目,因此尝试直接运行sbt。 在空文件夹中运行:sbt 并获取: Getting org.scala-sbt sbt 1.
我的网站上的 Facebook 登录遇到了一个奇怪的问题。这是全新的东西,Facebook 登录始终正常工作,并且仍在我的 Android 和 iOS 应用程序上工作。 我在网站上有一个链接,例如:
我正在尝试从其 pid 获取进程名称。用户以管理员身份运行,UAC 已启用,但未提升。 某些系统进程(例如 services.exe)的安全设置导致 OpenProcess(PROCESS_QUERY
我目前已经走进了 OAuth2 的世界,并对它有了一些的了解。我正在尝试制作一个应用程序,您可以在其中授权 Discord 帐户并让它自动邀请您加入公会/服务器。 我正在 Nginx 代理后面使用 E
我正在尝试从其 pid 中获取进程名称。用户以管理员身份运行,启用 UAC,但未提升权限。 一些系统进程,如 services.exe,以这样的方式设置它们的安全性 OpenProcess(PROCE
我是一名优秀的程序员,十分优秀!