ARCore Cloud Anchor Management API를 사용하여 ARCore 앱 외부에서 클라우드 앵커를 관리합니다.
시작하기
연산 예
승인
Google Cloud Platform 콘솔에서 서비스 계정 키를 만들고 Cloud Anchor Management API 호출을 승인하기 위한 OAuth2 토큰을 생성합니다.
Google Cloud Platform Console의 탐색 메뉴에서 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
새 토큰을 생성하려면 fetch
명령어에 --cache=""
옵션을 추가합니다.
oauth2l fetch --cache="" --json creds.json arcore.management
또는 oauth2l reset
를 호출하고 fetch
명령어를 다시 호출합니다.
oauth2l reset
oauth2l 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
의 기본값은 expire_time_desc
입니다.
클라우드 앵커의 TTL(수명)을 허용되는 최대 시간으로 업데이트
단일 클라우드 앵커에 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" ]}'