با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
انتخاب پلت فرم:
ویژگیهای ARCore مانند Geospatial API و Cloud Anchors از ARCore API میزبانی شده در Google Cloud استفاده میکنند. هنگام استفاده از این ویژگی ها، برنامه شما از اعتبارنامه ها برای دسترسی به سرویس ARCore API استفاده می کند.
این شروع سریع نحوه تنظیم برنامه خود را به گونه ای که بتواند با سرویس ARCore API میزبانی شده در Google Cloud ارتباط برقرار کند، توضیح می دهد.
یک پروژه Google Cloud جدید ایجاد کنید یا از یک پروژه موجود استفاده کنید
یک برنامه iOS می تواند با استفاده از دو روش مختلف مجوز با ARCore API ارتباط برقرار کند: مجوز بدون کلید، که روش توصیه شده است، و مجوز کلید API:
مجوز بدون کلید از یک نشانه امضا شده برای کنترل دسترسی به API استفاده می کند. این روش به سروری که متعلق به شماست نیاز دارد تا توکنها را امضا کند و دسترسی به API را کنترل کند.
کلید API رشتهای است که پروژه Google Cloud را شناسایی میکند. کلیدهای API معمولاً ایمن در نظر گرفته نمی شوند زیرا معمولاً برای مشتریان قابل دسترسی هستند. استفاده از مجوز Token را برای برقراری ارتباط با ARCore API در نظر بگیرید.
بدون کلید
ARCore از مجوز تماسهای API در iOS با استفاده از یک ( JSON Web Token ) پشتیبانی میکند. رمز باید توسط حساب Google Service امضا شده باشد.
برای ایجاد توکن برای iOS، باید یک نقطه پایانی در سرور خود داشته باشید که شرایط زیر را برآورده کند:
مکانیسم مجوز خود شما باید از نقطه پایانی محافظت کند.
نقطه پایانی باید هر بار یک توکن جدید تولید کند، به این صورت که:
هر کاربر یک توکن منحصر به فرد دریافت می کند.
توکن ها فورا منقضی نمی شوند.
یک حساب سرویس و کلید امضا ایجاد کنید
برای ایجاد حساب سرویس Google و کلید امضا، مراحل زیر را دنبال کنید:
در Google Cloud، صفحه اعتبارنامه را باز کنید. اعتبارنامه
روی ایجاد اعتبارنامه > حساب سرویس کلیک کنید.
در بخش جزئیات حساب سرویس ، یک نام برای حساب جدید تایپ کنید، سپس روی ایجاد کلیک کنید.
در صفحه مجوزهای حساب سرویس، به منوی کشویی Select a role بروید. حسابهای خدمات > ایجاد کننده رمز حساب حساب را انتخاب کنید، سپس روی ادامه کلیک کنید.
در صفحه Grant users access to this service account page، روی Done کلیک کنید.
در صفحه Credentials ، بخش Service Accounts را پیدا کنید و روی نام حسابی که ایجاد کرده اید کلیک کنید.
در صفحه جزئیات حساب سرویس ، به بخش کلیدها بروید و افزودن کلید > ایجاد کلید جدید را انتخاب کنید.
JSON را به عنوان نوع کلید انتخاب کنید و روی Create کلیک کنید.
این یک فایل JSON حاوی کلید خصوصی دستگاه شما را دانلود می کند. فایل کلید JSON دانلود شده را در مکانی امن ذخیره کنید.
توکن ها را روی سرور خود ایجاد کنید
برای ایجاد نشانه های جدید (JWT) در سرور خود، از کتابخانه های استاندارد JWT و فایل JSON که به طور ایمن از حساب سرویس جدید خود دانلود کرده اید استفاده کنید.
توکن ها را در ماشین توسعه خود ایجاد کنید
برای تولید JWT در ماشین توسعه خود، از دستور oauth2l زیر استفاده کنید:
تعیین یک مکان خالی کش با استفاده از پرچم --cache برای اطمینان از اینکه هر بار یک توکن متفاوت تولید می شود ضروری است. حتما رشته حاصل را کوتاه کنید. فاصله های اضافی یا نویسه های خط جدید باعث می شود API رمز را رد کند .
توکن را امضا کنید
برای امضای JWT باید از الگوریتم RS256 و ادعاهای زیر استفاده کنید:
iss - آدرس ایمیل حساب سرویس.
sub - آدرس ایمیل حساب سرویس.
iat - زمان یونیکس که توکن تولید شد، در ثانیه.
exp — iat + 3600 (1 ساعت). زمان یونیکس زمانی که توکن منقضی می شود، در ثانیه.
aud - مخاطب. باید رویhttps://arcore.googleapis.com/ تنظیم شود.
ادعاهای غیر استاندارد در بار JWT مورد نیاز نیست، اگرچه ممکن است ادعای uid برای شناسایی کاربر مربوطه مفید باشد.
اگر از روش دیگری برای تولید JWT های خود استفاده می کنید، مانند استفاده از Google API در یک محیط مدیریت شده توسط Google، مطمئن شوید که JWT های خود را با ادعاهای موجود در این بخش امضا کنید. مهمتر از همه، مطمئن شوید که مخاطب درست است.
رمز را در جلسه ARCore پاس کنید
اکنون برنامه شما برای استفاده از احراز هویت بدون کلید پیکربندی شده است.
هنگام ارسال توکن به جلسه به موارد زیر توجه کنید:
اگر از یک کلید API برای ایجاد جلسه استفاده کرده اید، ARCore توکن را نادیده می گیرد و یک خطا را ثبت می کند.
اگر دیگر به کلید API نیاز ندارید، آن را در Google Developers Console حذف کرده و از برنامه خود حذف کنید.
ARCore توکن هایی که حاوی فاصله یا کاراکترهای خاص هستند را نادیده می گیرد.
توکن ها معمولا پس از یک ساعت منقضی می شوند. اگر این احتمال وجود دارد که توکن شما در حین استفاده منقضی شود، یک توکن جدید تهیه کنید و آن را به API ارسال کنید.
کلید API
در Google Cloud، صفحه اعتبارنامه را باز کنید. اعتبارنامه
روی Create credentials کلیک کنید، سپس کلید API را از منو انتخاب کنید. گفتگوی ایجاد شده کلید API رشته کلید تازه ایجاد شده شما را نمایش می دهد.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[[["\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)"]]