尝试获取 Google accessToken

2024-05-18

看起来,无论我做什么,谷歌都在竭尽全力阻止我完成这个研究项目。我的项目让我使用 Google 电子表格作为数据库,并使用所述电子表格中的数据执行程序化的 Google 图片搜索,并向最终用户显示一些结果。

设置说明

我开始按照此处的说明进行操作:https://github.com/asimlqt/php-google-spreadsheet-client https://github.com/asimlqt/php-google-spreadsheet-client。我下载了Composer https://getcomposer.org/doc/00-intro.md#installation-windows到我的计算机,然后按照说明进行操作here https://github.com/asimlqt/php-google-spreadsheet-client#installation and here https://developers.google.com/api-client-library/php/start/installation让 Composer 将必要的库下载到我的项目中。

编码过程从那里开始,我尝试复制什么this guy https://stackoverflow.com/questions/21470405/google-api-how-to-connect-to-receive-values-from-spreadsheet他的回答中正在做。事实上,这是我的代码:

<?php
    require "vendor/autoload.php";
    //require '/php-google-spreadsheet-client-master\src\Google\Spreadsheet\Autoloader.php';

    use Google\Spreadsheet\DefaultServiceRequest;
    use Google\Spreadsheet\ServiceRequestFactory;

    const GOOGLE_CLIENT_ID = 'someClientID'; // here, I just pulled the default client ID from my Google Developers account
    const GOOGLE_CLIENT_EMAIL = 'someClientEmail'; // I used the default client email here as well, again, straight from Google Developers account
    const GOOGLE_CLIENT_KEY = 'someKey'; // I used the key that I used for the Google Custom Search Engine 
    const GOOGLE_CLIENT_KEY_PATH = 'vendor\google\apiclient\examples\key.p12'; // I did a search on my project folder for the .p12 file that had the key information, and used that path here
    const G_CLIENT_KEY_PW   = 'notasecret'; // the default (I don't know why I need to do this)

    // setup the googleClient
    $googleClient = new Google_Client();
    $googleClient->setApplicationName('future-graph-611');
    $googleClient->setClientId(GOOGLE_CLIENT_ID);
    $googleClient->setAssertionCredentials(new Google_Auth_AssertionCredentials(
        GOOGLE_CLIENT_EMAIL,
        array('https://spreadsheets.google.com/feeds','https://docs.google.com/feeds'), 
        file_get_contents(GOOGLE_CLIENT_KEY_PATH),  // Why can't I use the hard-coded GOOGLE_CLIENT_KEY here?
        G_CLIENT_KEY_PW
    ));
    //$googleClient->setAccessType('offline');
    // get an accessToken
    try
    {
        $googleClient->getAuth()->refreshTokenWithAssertion();  // the problem is here, on this line
    }
    catch (Google_Auth_Exception $exception)
    {
        echo $exception->getMessage();
    }
    $accessToken = json_decode($googleClient->getAccessToken());
    $accessToken = $accessToken->access_token;
?>

由于某种原因,try 块中的语句抛出 Exception: Errorfreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }' 。

我到底做错了什么?我还需要做什么才能使其发挥作用?


我想我在这里找到了问题的答案:https://github.com/asimlqt/php-google-spreadsheet-client/issues/24 https://github.com/asimlqt/php-google-spreadsheet-client/issues/24

/* 由于某种原因,他们在线上遇到了麻烦CURLOPT_SSL_VERIFYPEER => true(并通过将该索引设置为来修复它false) */

Also, echo $SpencerWieczorek->getResponse($this->getQuestion());

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

尝试获取 Google accessToken 的相关文章

随机推荐

  • 验证/操作多租户 Web API 中的输入参数

    假设我们有一个多租户博客应用程序 该应用程序的每个用户可能拥有多个由该服务托管的博客 我们的 API 允许读取和写入博客文章 在某些情况下 指定 BlogId 是可选的 例如 获取用 ASP NET 标记的所有帖子 api posts ta
  • 如何将 kubectl 配置文件与 ~/.kube/config 合并?

    有没有一个简单的kubectl命令采取kubeconfig文件 包含 cluster context user 并将其合并到 kube config 文件作为附加上下文 Do this export KUBECONFIG kube conf
  • matlab中更快的插值方法

    我正在使用 interp1 来插值一些数据 temp 4 30 4 rand 365 10 depth 1 10 dz 0 5 define new depth interval bthD min depth dz max depth ne
  • 更改 3D 图形颜色 (matplotlib)

    我使用以下代码在 matplotlib 中绘制了 3D 图形 Previously defines lists of data to plot fig plt figure ax fig add subplot 111 projection
  • Redux - 从函数调用操作

    我正在尝试从函数调用 redux 操作 我调用该函数的组件已连接到商店 但是 如果我通过以下操作 它就不起作用 function myFunc action action 有没有办法通过参数传递动作 谢谢 using bindActionC
  • 从 arraylist 和 hashmap 中删除重复项

    我有一个数组列表 其中包含付款人的姓名 另一个数组列表包含每次付款的费用 例如 nameArray 尼古拉 劳尔 洛伦佐 劳尔 劳尔 洛伦佐 尼古拉 价格数组 24 12 22 18 5 8 1 我需要将每个人的费用相加 所以数组必须变成
  • 如何用C++实现自然排序算法?

    我正在对由文本和数字组成的字符串进行排序 我希望排序将数字部分排序为数字 而不是字母数字 例如我想要 abc1def abc9def abc10def 而不是 abc10def abc1def abc9def 有谁知道这个的算法 特别是在c
  • p2p 通信中的对等方如何相互验证?

    WebRTC 中的对等点如何相互验证 WebRTC 中的 DTLS 使用自签名证书 RFC 5763 https www rfc editor org rfc rfc5763具有详细信息 简而言之 证书指纹与 SDP 的 a fingerp
  • 跟踪循环迭代

    抛硬币 成功 你赢100 否则你输50 你会一直玩 直到你口袋里有钱a 的价值如何a在任何迭代中都被存储 a lt 100 while a gt 0 if rbinom 1 1 0 5 1 a lt a 100 else a lt a 50
  • Java .drawImage:如何“取消绘制”或删除图像?

    我需要在程序运行时不断在不同位置重绘某个图像 因此 我设置了一个 while 循环 该循环应该在屏幕上移动图像 但它只是一遍又一遍地重新绘制图像 我究竟做错了什么 有没有办法在将旧图像绘制到新位置之前删除旧图像 JFrame frame b
  • 如何使用 Spring Crud/Jpa Repository 实现 DDD

    我想通过使用 Spring 实现 DDD 来创建一个应用程序 假设我有一个业务实体 Customer 和一个接口 CustomerRepository 由于春天提供了CrudRepository and JpaRepository默认情况下
  • 为什么我不能在 Realm 属性上使用 private

    我正在尝试在 RealmSwift 中存储一个枚举案例 但 Realm 不支持枚举 本文 https medium com it works locally persisting swift enumerations with realm
  • SQLite CreateDatabase 不支持错误

    我将 Entity Framework 4 2 CF 与 SQLite 一起使用 但是当我尝试启动该应用程序时 出现 提供商不支持 CreateDatabase 错误 这是我的模型映射 protected override void OnM
  • 覆盖XMLHttpRequest以实现跨域请求

    我想知道是否有一个 JavaScript 库可以覆盖XMLHttpRequest并允许透明地处理所有跨域请求 并通过我的同源服务器端代理无缝转发它们 我想要的是有一个通用的解决方案 可以与any用于发出跨域请求的 JavaScript 库
  • 如何获取 Python 中所有内置函数的列表?

    我正在尝试整理一个关于如何获取 Python 中所有内置函数的列表的规范示例 该文档很好 但我想用可证明的方法来演示它 在这里 我本质上将内置函数定义为默认命名空间的成员 这些成员可用且与旨在在模块中使用的函数的风格特征一致 即 它们提供一
  • SQL Server:将表达式转换为数据类型 bigint 时出现算术溢出错误

    这是我的查询顺序 SELECT CASE WHEN BarCode IS NOT NULL AND ExternelBarCode IS NULL THEN BarCode WHEN BarCode IS NULL AND Externel
  • 创建 Facebook 测试用户时访问令牌出现问题

    我正在尝试为我的 Facebook 应用程序创建测试用户 他们在 11 月份的博客文章 http developers facebook com blog post 429 中宣布了此功能 并在此处记录了该功能 http developer
  • 如何在使用 ajax 和 JQuery 时加密发布数据?

    服务器端我们可以对用户进行身份验证 但我希望 ajax 或 JQuery 发送数据时数据安全 就像在客户端一样 某人只能看到加密格式的任何调用的参数 那么我该怎么做呢 我在这个网站上看到过这个场景 EDIT 当数据来自服务器时 我们可以忽略
  • SSRS - RDLC Tablix 行不会跨页面拆分

    我有一个包含两列数据的 Tablix 部分名称和部分文本 对于某些部分 部分文本变得如此之大 以至于代表该部分的行占据了页面的 2 3 或更多 报告打印得很好 直到这些大行中的其中一个必须在页面末尾拆分并继续在下一页上 在这种情况下 并且仅
  • 尝试获取 Google accessToken

    看起来 无论我做什么 谷歌都在竭尽全力阻止我完成这个研究项目 我的项目让我使用 Google 电子表格作为数据库 并使用所述电子表格中的数据执行程序化的 Google 图片搜索 并向最终用户显示一些结果 设置说明 我开始按照此处的说明进行操