首页 > 解决方案 > 谷歌云函数 REST API 身份验证

问题描述

我想使用 Google 提供的以下 API:https ://cloud.google.com/functions/docs/reference/rest/

我向端点发出GET /v1/{name}/locations请求并收到 HTTP 401 错误。这意味着我没有设置身份验证。作为参考,这是我正在运行的代码:

import requests

def list(project_id):
    endpoint = 'https://cloudfunctions.googleapis.com/v1/projects/'
    endpoint += project_id
    endpoint += '/locations'
    r = requests.get(endpoint)
    return r

链接的文档指出,我需要拥有以下两个 OAuth 范围之一:

https://www.googleapis.com/auth/cloudfunctions

https://www.googleapis.com/auth/cloud-platform

我如何获得这些范围?我已经下载了凭证文件并导出了此处文档中列出的环境变量。我目前没有在任何地方使用这些凭据,因为通过纯文本发送私钥似乎存在安全风险。

有人可以解释如何将此 401 身份验证错误转换为 200 成功(或任何其他错误)吗?

标签: oauth-2.0google-cloud-platformgoogle-cloud-functionsrestful-authentication

解决方案


推荐阅读