ניהול עוגנים בענן מחוץ לאפליקציית ARCore באמצעות ARCore Cloud anchor Management API.
תחילת העבודה
פעולות לדוגמה
הרשאות
יוצרים מפתח לחשבון שירות במסוף Google Cloud Platform, ויוצרים אסימון 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
הוא היקף ה-OAuth של Cloud anchors Management API. כברירת מחדל, 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 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
, יופיעו עוגנים נוספים ברשימה. השתמשו בפרמטר של השאילתה 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 כדי לשלוח שאילתה ל-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 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"
מחיקת קבוצה של עוגנים בענן:
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" ]}'