קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
בחירת פלטפורמה:
תכונות ARCore כמו גיאו-מרחבי
ב-API וב-Cloud עוגנים משתמשים
ARCore API מתארח ב-Google Cloud. בזמן השימוש בתכונות האלה, האפליקציה
משתמש בפרטי הכניסה כדי לגשת לשירות ARCore API.
המדריך למתחילים הזה מתאר איך להגדיר את האפליקציה כך
לתקשר עם שירות ARCore API שמתארח ב-Google Cloud.
יצירת פרויקט חדש ב-Google Cloud או שימוש בפרויקט קיים
אפליקציה ל-iOS יכולה לתקשר עם ARCore API באמצעות
שיטות הרשאה: הרשאה ללא מפתחות,
והשיטה המומלצת, והרשאה באמצעות מפתח API:
בהרשאה ללא מפתח נעשה שימוש באסימון חתום כדי לשלוט בגישה ל-API. הזה
השיטה דורשת שרת שנמצא בבעלותך כדי לחתום על אסימונים ולשלוט בגישה אל
ממשק ה-API.
מפתח API הוא מחרוזת שמזהה פרויקט ב-Google Cloud. מפתחות ה-API הם:
בדרך כלל לא נחשבים מאובטחים, כי בדרך כלל הם נגישים ללקוחות.
כדאי להשתמש בהרשאת אסימון כדי לתקשר עם ARCore API.
ללא מפתח
ARCore תומך בהרשאה של קריאות ל-API ב-iOS באמצעות (JSON Web)
). האסימון חייב להיות חתום על ידי Google
חשבון שירות.
כדי ליצור אסימונים ל-iOS, צריך שתהיה לך נקודת קצה בשרת
שעומד בדרישות הבאות:
מנגנון ההרשאה שלכם חייב להגן על נקודת הקצה.
נקודת הקצה צריכה ליצור אסימון חדש בכל פעם, כך:
כל משתמש מקבל אסימון ייחודי.
התוקף של האסימונים לא פג באופן מיידי.
יצירת חשבון שירות ומפתח חתימה
כדי ליצור חשבון שירות ומפתח חתימה של Google, יש לפעול לפי השלבים הבאים:
ב-Google Cloud, פותחים את הדף Credentials. פרטי כניסה
לוחצים על Create Credentials > חשבון שירות.
בקטע פרטי חשבון שירות, מקלידים שם לחשבון החדש ולוחצים על
יצירה.
בדף 'הרשאות חשבון שירות', לוחצים על התפריט הנפתח בחירת תפקיד.
בוחרים באפשרות חשבונות שירות > יצירת אסימונים בחשבון שירות, ואז לוחצים על
המשך.
בדף Grant users access to this service account, לוחצים על Done.
בדף Credentials
מוצאים את הקטע 'חשבונות שירות' ולוחצים על שם החשבון
שאתם יצרתם.
בדף Service account details, גוללים למטה לקטע 'מפתחות'.
בוחרים באפשרות הוספת מפתח > יצירת מפתח חדש.
בוחרים באפשרות JSON בתור סוג המפתח ולוחצים על יצירה.
תתבצע הורדה של קובץ JSON שמכיל את המפתח הפרטי למחשב שלכם. חנות
את קובץ מפתח ה-JSON שהורדתם נמצא במיקום מאובטח.
יצירת אסימונים בשרת
כדי ליצור אסימונים חדשים (JWT) בשרת שלכם, צריך להשתמש בקוד ה-JWT הרגיל
ספריות
ואת קובץ ה-JSON שהורדתם באופן מאובטח מחשבון השירות החדש.
יצירת אסימונים במכונת הפיתוח
כדי ליצור אסימוני JWT במכונת הפיתוח, צריך להשתמש
הפקודה oauth2l:
ציון מיקום מטמון ריק באמצעות הדגל --cache הכרחי כדי
להבטיח שיופק אסימון שונה בכל פעם. חשוב להקפיד לחתוך את
המחרוזת שמתקבלת. רווחים מיותרים או תווים בשורה חדשה יגרמו ל-API:
לדחות את האסימון.
חתימה על האסימון
כדי לחתום על ה-JWT, עליכם להשתמש באלגוריתם RS256 ובהצהרות הבאות:
iss – כתובת האימייל של חשבון השירות.
sub – כתובת האימייל של חשבון השירות.
iat – תקופת הזמן (epoch) של יוניקס שבה נוצר האסימון, בשניות.
exp — iat + 3600 (שעה אחת). נקודת הזמן של מערכת יוניקס (Unix epoch) שבה פג תוקף האסימון,
בשניות.
aud – הקהל. צריך להיות מוגדר לערךhttps://arcore.googleapis.com/.
הצהרות לא סטנדרטיות לא נדרשות במטען הייעודי (payload) של JWT, אבל יכול להיות
ההצהרה uid שימושית לזיהוי המשתמש המתאים.
אם אתם משתמשים בגישה אחרת כדי ליצור את אסימוני ה-JWT, כמו שימוש
API בסביבה שמנוהלת על ידי Google, יש להקפיד לחתום על אסימוני ה-JWT עם ההצהרות
בקטע הזה. מעל לכל, חשוב לוודא שהקהל נכון.
העברת האסימון בסשן ARCore
האפליקציה שלך מוגדרת עכשיו לשימוש באימות ללא מפתח.
כשמעבירים אסימון לסשן, חשוב לשים לב לדברים הבאים:
אם השתמשתם במפתח API כדי ליצור את הסשן, ARCore תתעלם
ולרשום שגיאה.
אם אתם לא צריכים יותר את מפתח ה-API, אפשר למחוק אותו מ-Google Developers
המסוף ומסירים אותו
אפליקציה.
מערכת ARCore מתעלמת מאסימונים שמכילים רווחים או תווים מיוחדים.
בדרך כלל, תוקף האסימונים פג לאחר שעה. אם יש אפשרות
תוקף האסימון עשוי לפוג בזמן השימוש, עליכם לקבל אסימון חדש ולהעביר אותו ל-API.
מפתח ממשק API
ב-Google Cloud, פותחים את הדף Credentials. פרטי כניסה
לוחצים על Create credentials ובתפריט בוחרים באפשרות API key.
תיבת הדו-שיח של מפתח API שנוצר מציגה את המחרוזת של המפתח החדש שיצרתם.
[null,null,["עדכון אחרון: 2025-07-26 (שעון UTC)."],[[["\u003cp\u003eConfigure your application to communicate with the ARCore API service hosted on Google Cloud for features like Geospatial API and Cloud Anchors.\u003c/p\u003e\n"],["\u003cp\u003eSet up authorization using Keyless authorization (recommended) with JWT or API Key authorization, by enabling the ARCore API and creating necessary credentials.\u003c/p\u003e\n"],["\u003cp\u003eFor Keyless authorization, generate JWTs on your server or development machine with specific claims and pass the token in the ARCore session securely.\u003c/p\u003e\n"],["\u003cp\u003eFor API Key authorization, create an API key in Google Cloud and securely integrate it into your application while adhering to API key restrictions.\u003c/p\u003e\n"],["\u003cp\u003eOnce authorization is configured, explore ARCore features such as Geospatial API and Cloud Anchors that utilize it.\u003c/p\u003e\n"]]],["To access ARCore features like Geospatial API and Cloud Anchors, you must enable the ARCore API in your Google Cloud project. For iOS apps, keyless authorization (using JSON Web Tokens signed by a Google Service account) is recommended. This method involves creating a service account, generating a JSON key file, and creating tokens on your server with specific claims (iss, sub, iat, exp, aud). Alternatively, API keys can be used but are less secure. Your application can then pass the token or api key to the ARCore session.\n"],null,["# Use the ARCore API on Google Cloud\n\n**Select platform:** Android Unity (AR Foundation) iOS\n\nARCore features such as the [Geospatial\nAPI](/ar/develop/geospatial) and [Cloud Anchors](/ar/develop/cloud-anchors) use the\nARCore API hosted on Google Cloud. When using these features, your application\nuses credentials to access the ARCore API service.\n\nThis quickstart describes how to set up your application so that it can\ncommunicate with the ARCore API service hosted on Google Cloud.\n\nCreate a new Google Cloud project or use an existing project\n------------------------------------------------------------\n\nIf you have an existing project, select it.\n\n[Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n\nIf you don't have an existing Google Cloud project, create one.\n\n[Create new project](https://console.cloud.google.com/projectcreate)\n\nEnable the ARCore API\n---------------------\n\nTo use the ARCore API, you must enable it in your project.\n\n[Enable the ARCore API](https://console.cloud.google.com/apis/library/arcore)\n\n\u003cbr /\u003e\n\nSet up an authorization method\n------------------------------\n\nAn iOS application can communicate with the ARCore API using two different\nauthorization methods: Keyless authorization, which is the\nrecommended method, and API Key authorization:\n\n- Keyless authorization uses a token signed to control access to the API. This method requires a server owned by you to sign tokens and control access to the API.\n- An API key is a string that identifies a Google Cloud project. API keys are generally not considered secure as they are typically accessible to clients. Consider using Token authorization to communicate with the ARCore API.\n\n### Keyless\n\n\nARCore supports the authorization of API calls in iOS using a ([JSON Web\ntoken](https://jwt.io/)). The token must be signed by a Google\nService account.\n\nIn order to generate tokens for iOS, you must have an endpoint on your server\nthat satisfies the following requirements:\n\n- Your own authorization mechanism must protect the endpoint.\n\n- The endpoint must generate a new token every time, such that:\n\n - Each user gets a unique token.\n - Tokens don't immediately expire.\n\n### Create a service account and signing key\n\nFollow these steps to create a Google service account and signing key:\n\n1. In Google Cloud, open the Credentials page. \n [Credentials](https://console.cloud.google.com/apis/credentials)\n2. Click **Create Credentials \\\u003e Service account**.\n3. Under **Service account details** , type a name for the new account, then click **Create**.\n4. On the Service account permissions page, go to the **Select a role** drop-down. Select **Service Accounts \\\u003e Service Account Token Creator**, then click Continue.\n5. On the **Grant users access to this service account** page, click Done.\n6. On the [Credentials](https://console.cloud.google.com/apis/credentials) page, find the Service Accounts section and click the name of the account you just created.\n7. On the **Service account details** page, scroll down to the Keys section and select **Add Key \\\u003e Create new key**.\n8. Select **JSON** as the key type and click **Create**.\n\n This downloads a JSON file containing the private key to your machine. Store\n the downloaded JSON key file in a secure location.\n | **Note:** This file contains a private key which must not be exposed to the public. Do **not** commit it to source code repositories like GitHub.\n\n### Create tokens on your server\n\nTo create new tokens (JWTs) on your server, use the [standard JWT\nlibraries](https://jwt.io/#libraries-io)\nand the JSON file that you securely downloaded from your new service account.\n\n### Create tokens on your development machine\n\nTo generate JWTs on your development machine, use the following\n[`oauth2l`](https://github.com/google/oauth2l) command: \n\n```\noauth2l fetch --cache \"\" --jwt --json $KEYFILE --audience \"https://arcore.googleapis.com/\"\n```\n\nSpecifying an empty cache location using the `--cache` flag is necessary to\nensure that a different token is produced each time. Be sure to trim the\nresulting string. **Extra spaces or newline characters will cause the API to\nreject the token**.\n\n### Sign the token\n\nYou must use the `RS256` algorithm and the following claims to sign the JWT:\n\n- `iss` --- The service account email address.\n- `sub` --- The service account email address.\n- `iat` --- The Unix epoch time when the token was generated, in seconds.\n- `exp` --- `iat` + `3600` (1 hour). The Unix epoch time when the token expires, in seconds.\n- `aud` --- The audience. **It must be set to** `https://arcore.googleapis.com/`.\n\nNon-standard claims are not required in the JWT payload, though you may find the\n`uid` claim useful for identifying the corresponding user.\n\nIf you use a different approach to generate your JWTs, such as using a Google\nAPI in a Google-managed environment, make sure to sign your JWTs with the claims\nin this section. Above all, make sure that the audience is correct.\n\n### Pass the token in the ARCore session\n\nYour app is now configured to use Keyless authentication.\n\nNote the following when you pass a token into the session:\n\n- If you have used an API key to create the session, ARCore will ignore the\n token and log an error.\n\n If you no longer need the API key, delete it in the [Google Developers\n Console](https://console.developers.google.com/) and remove it from your\n app.\n- ARCore ignores tokens that contain spaces or special characters.\n\n- Tokens typically expire after one hour. If there is a possibility that your\n token may expire while in use, obtain a new token and pass it to the API.\n\n### API Key\n\n\n1. In Google Cloud, open the Credentials page. \n [Credentials](https://console.cloud.google.com/apis/credentials)\n2. Click **Create credentials** , then select **API key** from the menu. \n The API key created dialog displays the string for your newly created key.\n3. \n4. Review [documentation on API key restrictions](https://cloud.google.com/docs/authentication/api-keys#api_key_restrictions) to secure your API key.\n\nYour app is now configured to use API keys.\n\nWhat's next\n-----------\n\nWith authorization configured, check out the following ARCore features that use\nit:\n\n- [Geospatial API](/ar/develop/geospatial)\n- [Cloud Anchor API](/ar/develop/cloud-anchors)"]]