نشانه های جلسه
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
تکمیل خودکار مکان (میراث) از نشانههای جلسه برای گروهبندی مراحل پرس و جو و انتخاب جستجوی تکمیل خودکار کاربر در یک جلسه مجزا برای اهداف صورتحساب استفاده میکند. جلسه زمانی شروع می شود که کاربر شروع به تایپ یک پرس و جو می کند، و زمانی که یک مکان را انتخاب می کند و تماسی با جزئیات مکان (میراث) برقرار می شود، به پایان می رسد. هر جلسه می تواند چندین پرس و جو تکمیل خودکار داشته باشد و به دنبال آن یک مکان انتخاب شود. کلید(های) API مورد استفاده برای هر درخواست در یک جلسه باید متعلق به همان پروژه کنسول Google Cloud باشد. پس از پایان جلسه، رمز دیگر معتبر نیست. برنامه شما باید برای هر جلسه یک توکن جدید تولید کند. اگر پارامتر sessiontoken
حذف شود، یا اگر از یک نشانه جلسه استفاده مجدد کنید، هزینه جلسه به گونه ای محاسبه می شود که گویی هیچ نشانه جلسه ارائه نشده است (هر درخواست جداگانه صورتحساب می شود).
ما دستورالعمل های زیر را توصیه می کنیم:
- از نشانههای جلسه برای تمام جلسات تکمیل خودکار استفاده کنید.
- برای هر جلسه یک نشانه جدید ایجاد کنید .
- اطمینان حاصل کنید که کلید(های) API مورد استفاده برای همه درخواستهای تکمیل خودکار مکان (قدیمی) و جزئیات مکان (قدیمی) در یک جلسه متعلق به همان پروژه کنسول Google Cloud است.
- مطمئن شوید که برای هر جلسه جدید یک نشانه جلسه منحصر به فرد ارسال می کنید. استفاده از یک نشانه برای بیش از یک جلسه باعث می شود که هر درخواست به صورت جداگانه صورتحساب شود.
شما می توانید به صورت اختیاری نشانه تکمیل خودکار جلسه را از یک درخواست حذف کنید. اگر نشانه جلسه حذف شود، هر درخواست جداگانه صورتحساب میشود و SKU تکمیل خودکار - هر درخواست را راهاندازی میکند. اگر از یک نشانه جلسه استفاده مجدد کنید، جلسه نامعتبر تلقی می شود و درخواست ها به گونه ای محاسبه می شوند که گویی نشانه جلسه ارائه نشده است.
مثال
همانطور که کاربر یک پرس و جو را تایپ می کند، هر چند ضربه کلید (نه به ازای هر کاراکتر) یک درخواست تکمیل خودکار فراخوانی می شود و لیستی از نتایج ممکن برگردانده می شود. هنگامی که کاربر انتخابی را از لیست نتایج انجام می دهد، انتخاب به عنوان یک درخواست حساب می شود و همه درخواست های انجام شده در طول جستجو به صورت دسته بندی شده و به عنوان یک درخواست شمارش می شوند. اگر کاربر مکانی را انتخاب کند، درخواست جستجو بدون هزینه در دسترس است و فقط درخواست داده مکان هزینه می شود. اگر کاربر ظرف چند دقیقه پس از شروع جلسه انتخابی انجام ندهد، فقط درخواست جستجو شارژ می شود.
بیایید این جریان رویدادها را از منظر یک اپلیکیشن بررسی کنیم.
- کاربر شروع به تایپ یک پرس و جو برای جستجوی "پاریس، فرانسه" می کند.
- پس از شناسایی ورودی کاربر، برنامه یک نشانه جلسه جدید، "Token A" ایجاد می کند.
- همانطور که کاربر تایپ می کند، API هر چند کاراکتر یک درخواست تکمیل خودکار می کند و لیست جدیدی از نتایج بالقوه را برای هر یک نمایش می دهد:
"پ"
"پار"
"پاریس"
"پاریس، فر"
- هنگامی که کاربر انتخاب می کند:
- تمام درخواست های حاصل از پرس و جو گروه بندی می شوند و به عنوان یک درخواست به جلسه ارائه شده توسط "Token A" اضافه می شوند.
- انتخاب کاربر به عنوان یک درخواست جزئیات مکان شمارش می شود و به جلسه ای که با "Token A" نشان داده می شود اضافه می شود.
- جلسه به پایان می رسد و برنامه "Token A" را کنار می گذارد.
برای اطلاعات بیشتر در مورد نحوه صدور صورتحساب درخواستهای تکمیل خودکار مکان (قدیمی)، به استفاده و صورتحساب مراجعه کنید.
ایجاد نشانه های جلسه
برای ایجاد یک نشانه جلسه، AutocompleteSessionToken.newInstance()
را فراخوانی کنید.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Session Tokens\n\nSelect platform: [Android](/maps/documentation/places/android-sdk/session-tokens \"View this page for the Android platform docs.\") [iOS](/maps/documentation/places/ios-sdk/session-tokens \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/places-autocomplete#session_tokens \"View this page for the JavaScript platform docs.\") [Web Service](/maps/documentation/places/web-service/session-tokens \"View this page for the Web Service platform docs.\")\n\nPlace Autocomplete (Legacy) uses session tokens to group the query and selection\nphases of a user autocomplete search into a discrete session for billing\npurposes. The session begins when the user starts typing a query, and concludes\nwhen they select a place and a call to Place Details (Legacy) is made. Each session can\nhave multiple autocomplete queries, followed by one place selection. The API\nkey(s) used for each request within a session must belong to the same\nGoogle Cloud console project. Once a session has concluded, the token is no longer\nvalid; your app must generate a fresh token for each session. If the\n`sessiontoken` parameter is omitted, or if you reuse a session\ntoken, the session is charged as if no session token was provided (each request\nis billed separately).\n\nWe recommend the following guidelines:\n\n- Use session tokens for all autocomplete sessions.\n- [Generate a fresh token](#create-session-tokens) for each session.\n- Ensure that the API key(s) used for all Place Autocomplete (Legacy) and Place Details (Legacy) requests within a session belong to the same Google Cloud console project.\n- Be sure to pass a unique session token for each new session. Using the same token for more than one session will result in each request being billed individually.\n\nYou can optionally omit the autocomplete session token from a request. If\nthe session token is omitted, each request is billed separately, triggering the\n\n[Autocomplete - Per Request](/maps/billing-and-pricing/sku-details#autocomplete-request-new-ess-sku)\n\n\nSKU. If you reuse a session token, the session is considered invalid and the\nrequests are charged as if no session token was provided.\n\nExample\n-------\n\nAs the user types a query, an autocomplete request is called every few\nkeystrokes (not per-character), and a list of possible results is returned.\nWhen the user makes a selection from the result list, the selection counts as\na request, and all of the requests made during the search are bundled and\ncounted as a single request. If the user selects a place, the search query is\navailable at no charge, and only the Place data request is charged. If the user does not make a\nselection within a few minutes of the beginning of the session, only the\nsearch query is charged.\n\nLet's examine this flow of events from the perspective of an app.\n\n1. A user begins typing a query to search for \"Paris, France\".\n2. Upon detecting user input, the app creates a new session token, \"Token A\".\n3. As the user types, the API makes an autocomplete request every few characters, displaying a new list of potential results for each: \n \"P\" \n \"Par\" \n \"Paris,\" \n \"Paris, Fr\" \n4. When the user makes a selection:\n - All requests resulting from the query are grouped and added to the session represented by \"Token A\", as a single request.\n - The user's selection is counted as a Place Detail request, and added to the session represented by \"Token A\".\n5. The session is concluded, and the app discards \"Token A\".\n\nFor more information about how Place Autocomplete (Legacy) requests are billed, see\n\n[Usage and Billing](/maps/documentation/places/android-sdk/usage-and-billing).\n\nCreate session tokens\n---------------------\n\n\nTo create a session token, call\n[`AutocompleteSessionToken.newInstance()`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/model/AutocompleteSessionToken#newInstance())."]]