使用 FieldMask 更新数据
使用 API 更新代理数据时,您可以选择覆盖整个数据类型或仅覆盖数据类型的特定字段。通常情况下,最好覆盖特定字段,以免因意外覆盖所有数据。如要覆盖特定字段,请为更新请求提供 FieldMask
。
以下示例展示了如何提供 FieldMask
以更新 Intent
类型的显示名。
REST 和命令行
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 GCP 项目 ID
- AGENT_ID:您的代理 ID
- REGION_ID:您的区域 ID
- INTENT_ID:您的意图 ID
- DISPLAY_NAME:所需的显示名
HTTP 方法和网址:
PATCH https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID/intents/INTENT_ID?updateMask=displayName
请求 JSON 正文:
{
"displayName": "DISPLAY_NAME"
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X PATCH \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID/intents/INTENT_ID?updateMask=displayName"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID/intents/INTENT_ID?updateMask=displayName" | Select-Object -Expand Content
您应该会收到类似以下内容的 JSON 响应:
{
"name": "projects/your-project-id/locations/us-central1/agents/c2a370ca-158a-4296-a211-d5ab6bb84324/intents/91aa7827-d69b-4077-8b21-7a66b8b59f16",
"displayName": "your-display-name",
...
}
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-08-09 UTC.
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"很难理解"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"信息或示例代码不正确"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"没有我需要的信息/示例"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻译问题"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"易于理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"解决了我的问题"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]