调用 Method: purchases.subscriptions.get endpoint 时出现 UNAUTHENTICATED 错误

I get UNAUTHENTICATED error when I call Method: purchases.subscriptions.get endpoint

当我尝试从我的后端服务器调用 https://androidpublisher.googleapis.com/androidpublisher/v3/applications/{packageName}/purchases/subscriptions/{subscriptionId}/tokens/{token} 来验证我收到的购买时:

{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "errors": [
      {
        "message": "Login Required.",
        "domain": "global",
        "reason": "required",
        "location": "Authorization",
        "locationType": "header"
      }
    ],
    "status": "UNAUTHENTICATED"
  }
}

如何从我的 后端服务器 进行身份验证(因此没有任何用户界面)?有什么方法可以在某处创建 API 密钥 并使用它进行身份验证?

错误信息

Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

声明需要授权。

如果您查看 Method: purchases.subscriptions.get

的文档

您会注意到它声明此方法需要以下范围的授权

假设这是一个由您开发者控制的帐户,而您只想访问这个单一帐户,您应该考虑使用服务帐户进行授权。此处的文档 Using a service account