我在使用 Google 自定义搜索 API 时收到 403“调用方没有权限”错误,这是我以前从未收到过的

I am getting a 403 "The caller does not have permission" error when using the Google Custom Search API that I haven't gotten before

提问人:kelko 提问时间:10/14/2023 更新时间:10/14/2023 访问量:56

问:

当我调用 Google 自定义搜索 API 时,我收到以下错误:

{
  "error": {
    "code": 403,
    "message": "The caller does not have permission",
    "errors": [
      {
        "message": "The caller does not have permission",
        "domain": "global",
        "reason": "forbidden"
      }
    ],
    "status": "PERMISSION_DENIED"
  }
}

我以前多次使用过这个API,唯一的区别是我使用的是不同的Google云帐户和API密钥。我已经在我的 Google Cloud 项目中启用了自定义搜索 API,当我在 Google Cloud Console 中查看使用情况时,它显示 100% 错误,图表显示所有 403 个错误。我还启用了 Places API,它运行良好。为什么我会收到此错误?

我尝试设置 OAuth 同意屏幕,但我很确定这仅在我使用 OAuth 令牌而不是 API 密钥时才有意义,并且此 API 的文档仅告诉我如何使用 API 密钥。

云平台谷歌 自定义搜索

评论

0赞 kelko 10/14/2023
如果我使用 OAuth 客户端令牌来使用 Google Python 客户端库(我通过下载 OAuth 客户端 ID、通过脚本运行它并编辑脚本生成的 json 文件以添加“类型”来获得该令牌),则它可以工作。但是,这不是一个解决方案,因为我在 Google Apps 脚本中使用了 API,它没有这样的客户端库。

答: 暂无答案