ARCore Cloud Anchor Management API

使用 ARCore Cloud Anchor 管理 ARCore 應用程式之外的 Cloud Anchors Management API

開始使用

作業範例

授權

在 Google Cloud Platform Console 提供 OAuth2 權杖,用於授權 Cloud Anchor Management API 呼叫。

  1. 在 Google Cloud Platform 控制台,前往 APIs & Services >Credentials。

  2. 選取需要的專案,然後按一下「Create Credentials」>「Service account。

  3. 在「Service account details」下方輸入新帳戶的名稱,然後 按一下 Create。

  4. 前往「Service account permissions」頁面的「Select a role」 。「Service Accounts」>Service Account Token Creator, 然後按一下 Continue。

  5. 在 Grant users access to this service account 頁面中,按一下 Done。 這會帶您回到 APIs & Services >Credentials。

  6. 在「Credentials」頁面中,向下捲動至「Service Accounts」部分 然後按一下您剛建立的帳戶名稱

  7. 在「Service account details」頁面中,向下捲動至「Keys」部分 然後選取 Add Key >Create new key。

  8. 選取 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 reset
oauth2l fetch --json creds.json arcore.management

列出所有 Cloud 錨點

取得 Cloud Anchors 的第一頁,可選擇按照 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,就會有更多錨點 請參考閱讀清單,進一步瞭解 如何選擇 Kubeflow Pipelines SDK 或 TFX在下一個要求中使用 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 則預設為 expire_time_desc。

將 Cloud Anchor 的存留時間上限更新為允許時間上限

要求單一 Cloud Anchor 來查詢其 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"
}

刪除 Cloud 錨點

刪除單一 Cloud Anchor:

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"

刪除一批 Cloud Anchors:

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" ]}'