API quản lý neo trên đám mây ARCore

Quản lý Neo trên đám mây bên ngoài ứng dụng ARCore bằng cách sử dụng API Quản lý neo trên đám mây ARCore.

Bắt đầu

Toán tử mẫu

Ủy quyền

Tạo khoá tài khoản dịch vụ trong bảng điều khiển Google Cloud Platform và tạo mã thông báo OAuth2 để cho phép các lệnh gọi API quản lý Cloud Anchor.

  1. Trong trình đơn điều hướng của bảng điều khiển Google Cloud Platform, hãy chuyển đến APIs & Services > Credentials.

  2. Chọn dự án mà bạn muốn, sau đó nhấp vào Create Credentials > Service account.

  3. Trong Service account details, hãy nhập tên cho tài khoản mới, sau đó nhấp vào Create.

  4. Trên trang Service account permissions, hãy chuyển đến trình đơn thả xuống Select a role. Chọn Service Accounts > Service Account Token Creator, sau đó nhấp vào Continue.

  5. Trên trang Grant users access to this service account, hãy nhấp vào Done. Thao tác này sẽ đưa bạn trở lại APIs & Services > Credentials.

  6. Trên trang Credentials, hãy cuộn xuống phần Service Accounts rồi nhấp vào tên của tài khoản bạn vừa tạo.

  7. Trên trang Service account details, hãy di chuyển xuống phần Keys rồi chọn Add Key > Create new key.

  8. Chọn JSON làm loại khoá và nhấp vào Create. Thao tác này sẽ tải một tệp JSON chứa khoá riêng tư xuống máy của bạn. Lưu trữ tệp khoá JSON đã tải xuống ở một nơi an toàn.

Tạo mã thông báo OAuth2

arcore.management là phạm vi OAuth cho API Quản lý neo trên đám mây. Theo mặc định, OAuth2l hoạt động trên bộ nhớ đệm mã thông báo. Lệnh fetch truy xuất cùng một mã thông báo. Hãy dùng OAuth2l để tạo mã thông báo OAuth2 để uỷ quyền:

oauth2l fetch --json creds.json arcore.management

Để tạo mã thông báo mới, hãy thêm tuỳ chọn --cache="" vào lệnh fetch.

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

Ngoài ra, bạn có thể gọi oauth2l reset rồi gọi lại lệnh fetch.

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

Liệt kê tất cả Cloud Anchors

Tải trang đầu tiên của Cloud Anchors, tuỳ ý sắp xếp theo expire_time, create_time hoặc last_localize_time.

Yêu cầu:

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"

Phản hồi:

{
  "anchors": [
    {
      "name": "anchors/ua-a1cc84e4f11b1287d289646811bf54d1",
      "createTime": "...",
      "expireTime": "...",
      "lastLocalizeTime": "...",
      "maximumExpireTime": "..."
    },
   …
    {
      "name": "anchors/ua-41a3d0233471917875159f6f3c25ea0e",
      "createTime": "...",
      "expireTime": "...",
      "lastLocalizeTime": "...",
      "maximumExpireTime": "..."
    }
  ],
  nextPageToken: "some-long-string"
}

Nếu phản hồi trả về bằng một nextPageToken, thì sẽ có nhiều liên kết hơn trong danh sách. Sử dụng tham số truy vấn next_page_token trong yêu cầu tiếp theo để truy xuất nhóm kết quả tiếp theo.

Yêu cầu:

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"

Khi sử dụng next_page_token, page_sizeorder_by phải nhất quán giữa các yêu cầu. page_size mặc định là 1000order_by mặc định là expire_time_desc.

Cập nhật thời gian tồn tại của Cloud Anchor đến thời gian tối đa cho phép

Yêu cầu một Cloud Anchor duy nhất để truy vấn lastLocalizeTimemaximumExpireTime của đám mây.

Yêu cầu:

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"

Phản hồi:

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

Sau khi bạn có quảng cáo cố định, hãy cập nhật expireTime thành maximumExpireTime.

Yêu cầu:

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

Phản hồi:

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

Xoá Cloud Anchors

Xoá một 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"

Xoá một loạt 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" ]}'