ARCore Cloud Anchor Management API

ARCore Cloud Anchor Management API を使用して、ARCore アプリの外部で Cloud Anchors を管理します。

はじめに

オペレーションの例

承認

Google Cloud Platform コンソールでサービス アカウント キーを作成し、Cloud Anchor Management API 呼び出しを承認するための OAuth2 トークンを生成します。

  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

新しいトークンを生成するには、fetch コマンドに --cache="" オプションを追加します。

oauth2l fetch --cache="" --json creds.json arcore.management

または、oauth2l reset を呼び出して、fetch コマンドを再度呼び出します。

oauth2l reset
oauth2l fetch --json creds.json arcore.management

すべての Cloud アンカーを一覧表示する

Cloud Anchors の最初のページを取得します。必要に応じて expire_timecreate_timelast_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_sizeorder_by はリクエスト間で一貫している必要があります。page_size のデフォルトは 1000 で、order_by のデフォルトは expire_time_desc です。

Cloud Anchor の有効期間を許容される最大時間に更新

単一の Cloud Anchor をリクエストして、その lastLocalizeTimemaximumExpireTime をクエリします。

リクエスト:

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

アンカーを取得したら、その expireTimemaximumExpireTime に更新します。

リクエスト:

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 アンカーの削除

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