使用 ARCore 云锚点在您的 ARCore 应用之外管理云锚点 Management API。
使用入门
操作示例
授权
在以下位置创建服务账号密钥: Google Cloud Platform Console 并生成 OAuth2 令牌以授权 Cloud Anchor Management API 调用。
在 Google Cloud Platform 控制台,前往 APIs & Services >Credentials。
选择所需的项目,然后点击 Create Credentials >Service account。
在 Service account details 下,输入新账号的名称,然后 点击 Create。
在Service account permissions页面上,转到Select a role。 下拉菜单。选择 Service Accounts >Service Account Token Creator, 然后点击 Continue。
在 Grant users access to this service account 页面上,点击 Done。 您会返回到 APIs & Services >Credentials。
在“Credentials”页面上,向下滚动到“Service Accounts”部分 然后点击您刚刚创建的账号的名称。
在“Service account details”页面上,向下滚动到“Keys”部分 然后选择 Add Key >Create new key。
选择 JSON 作为密钥类型,然后点击 Create。这会下载一个 JSON 文件, 包含私钥的文件复制到您的计算机上。存储下载的 JSON 密钥文件保存在安全位置。
生成 OAuth2 令牌
arcore.management 是 Cloud Anchors Management API 的 OAuth 范围。修改者
默认情况下,oauth2l 适用于令牌缓存。fetch 命令检索与
令牌。使用 oauth2l 生成 OAuth2
用于授权的令牌:
oauth2l fetch --json creds.json arcore.management如需生成新令牌,请将 --cache="" 选项添加到 fetch
命令。
oauth2l fetch --cache="" --json creds.json arcore.management或者,调用 oauth2l reset 并再次调用 fetch 命令。
oauth2l resetoauth2l fetch --json creds.json arcore.management
列出所有云锚点
获取云锚点的第一页(可选择按 expire_time 排序),
create_time 或 last_localize_time。
请求:
export BEARER_TOKEN=`(oauth2l fetch --json creds.json arcore.management)`curl -H "Authorization: Bearer $BEARER_TOKEN" \
"https://arcore.googleapis.com/v1beta2/management/anchors?page_size=50&order_by=last_localize_time%20desc"
响应:
{
  "anchors": [
    {
      "name": "anchors/ua-a1cc84e4f11b1287d289646811bf54d1",
      "createTime": "...",
      "expireTime": "...",
      "lastLocalizeTime": "...",
      "maximumExpireTime": "..."
    },
   …
    {
      "name": "anchors/ua-41a3d0233471917875159f6f3c25ea0e",
      "createTime": "...",
      "expireTime": "...",
      "lastLocalizeTime": "...",
      "maximumExpireTime": "..."
    }
  ],
  nextPageToken: "some-long-string"
}
如果响应返回 nextPageToken,则会有更多锚点
列表。在下一个请求中使用 next_page_token 查询参数检索
下一组结果。
请求:
curl -H "Authorization: Bearer $BEARER_TOKEN" \
   "https://arcore.googleapis.com/v1beta2/management/anchors?page_size=50&order_by=last_localize_time%20desc&next_page_token=your-next-page-token-here"使用 next_page_token 时,page_size 和 order_by 必须一致
所有请求page_size 默认为 1000,order_by 默认为 1000
expire_time_desc。
将云锚点的存留时间更新为允许的最长存留时间
请求单个云锚点以查询其 lastLocalizeTime,并
maximumExpireTime。
请求:
export BEARER_TOKEN=`(oauth2l fetch --json creds.json arcore.management)`curl -H "Authorization: Bearer $BEARER_TOKEN" \
"https://arcore.googleapis.com/v1beta2/management/anchors/your-anchor-id-here"
响应:
{
  "name": "anchors/ua-f21be53fd8ea57f0169c69fbf827f6b7",
  "createTime": "2020-06-29T21:00:00Z",
  "expireTime": "2020-08-28T22:00:00Z",
  "lastLocalizeTime": "2020-06-29T21:00:00Z",
  "maximumExpireTime": "2021-06-29T21:00:00Z"
}
获得锚点后,请将其 expireTime 更新为 maximumExpireTime。
请求:
curl -H "Authorization: Bearer $BEARER_TOKEN" -H "Content-Type: application/json" -X "PATCH" \
   "https://arcore.googleapis.com/v1beta2/management/anchors/your-anchor-id-here?updateMask=expire_time" \
    -d '{ expireTime: "2021-06-29T21:00:00Z" }'响应:
{
  "name": "anchors/ua-f21be53fd8ea57f0169c69fbf827f6b7",
  "createTime": "2020-06-29T21:00:00Z",
  "expireTime": "2021-06-29T21:00:00Z",
  "lastLocalizeTime": "2020-06-29T21:00:00Z",
  "maximumExpireTime": "2021-06-29T21:00:00Z"
}
删除云锚点
删除单个云锚点:
export BEARER_TOKEN=`(oauth2l fetch --json creds.json arcore.management)`curl -H "Authorization: Bearer $BEARER_TOKEN" -X "DELETE" \
"https://arcore.googleapis.com/v1beta2/management/anchors/your-anchor-id-here"
删除一批云锚点:
export BEARER_TOKEN=`(oauth2l fetch --json creds.json arcore.management)`curl -H "Authorization: Bearer $BEARER_TOKEN" -H "Content-Type: application/json" -X "POST" \
"https://arcore.googleapis.com/v1beta2/management/anchors:batchDelete" \
-d '{ names: [ "anchors/your-anchor-id-here", "anchors/your-anchor-id-here" ]}'