0

我正在尝试将我的目录集成到谷歌推荐 ai 中,出于调试目的,我希望能够在导入后从目录中删除项目。文档建议运行以下代码:

curl -X DELETE \
 -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
"https://retail.googleapis.com/v2/projects/[PROJECT_NUMBER]/locations/global/catalogs/default_catalog/branches/0/products/[PRODUCT_ID]"

返回以下错误:

    {
  "error": {
    "code": 403,
    "message": "Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the retail.googleapis.com. We recommend configuring the billing/quota_project setting in gcloud or using a service account through the auth/impersonate_service_account setting. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "SERVICE_DISABLED",
        "domain": "googleapis.com",
        "metadata": {
          "service": "retail.googleapis.com",
          "consumer": "[redacted for privacy]"
        }
      }
    ]
  }

使用 --impersonate-service-account 标志运行建议的代码,会导致与上述相同的错误,但前面有

警告:检测到模拟服务帐户“[name redacted for privacy]”。此命令不能用于打印模拟帐户的访问令牌。下面的令牌仍然是应用程序默认凭据的访问令牌。

如果我尝试登录以进行授权而不是打印访问令牌,则会收到以下错误:

    {
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

提供的链接不再有效。我想知道如何为从推荐 ai 目录中删除项目提供适当的授权/身份验证。

PS。我用来执行此操作的帐户是项目的所有者,因此应该具有所有适当的权限。

4

1 回答 1

0

为您对 Recommendations AI 的本地 cURL 请求的应用程序设置身份验证。您必须创建一个 Service Account,下载 SA 密钥,并将环境变量“GOOGLE_APPLICATION_CREDENTIALS”设置为密钥,以便允许原始描述中注明的本地 cURL 请求

如果您无法下载 SA 密钥文件,我建议您尝试使用 ! 在这样的 curl 之前, !curl -X POST ,同样如果你熟悉 Python,建议使用Python 库 for Recommendations AI。

于 2021-07-27T23:46:45.353 回答