בתכונה 'השלמה אוטומטית למקומות' (מדור קודם) נעשה שימוש באסימוני סשן כדי לקבץ את שלבי השאילתה והבחירה בחיפוש של משתמש עם השלמה אוטומטית לסשן נפרד למטרות חיוב. הסשן מתחיל כשהמשתמש מתחיל להקליד שאילתה, ומסתיים כשהמשתמש בוחר מקום ומתבצעת קריאה ל-Place Details (Legacy). כל סשן יכול לכלול כמה שאילתות להשלמה אוטומטית, ואחריה בחירה של מקום אחד. מפתחות ה-API שמשמשים לכל בקשה בסשן חייבים להיות שייכים לאותו פרויקט במסוף Google Cloud. בסיום הסשן, האסימון כבר לא תקף. האפליקציה צריכה ליצור אסימון חדש לכל סשן. אם הפרמטר sessiontoken לא יצוין או אם תשתמשו שוב באסימון סשן, הסשן יחויב כאילו לא סופק אסימון סשן (כל בקשה מחויבת בנפרד).
חשוב לוודא שמפתחות ה-API שמשמשים לכל הבקשות של Place Autocomplete (מדור קודם) ושל פרטי מקום (מדור קודם) בסשן שייכים לאותו פרויקט במסוף Google Cloud.
חשוב להעביר אסימון סשן ייחודי לכל סשן חדש. שימוש באותו אסימון ביותר מסשן אחד יוביל לחיוב בנפרד על כל בקשה.
אפשר להשמיט את אסימון הסשן של ההשלמה האוטומטית מבקשה. אם משמיטים את אסימון הסשן, כל בקשה מחויבת בנפרד, וכתוצאה מכך מופעל המק"ט Autocomplete – Per Request. אם משתמשים שוב באסימון סשן, הסשן נחשב לא תקף והבקשות יחויבו כאילו לא סופק אסימון סשן.
דוגמה
כשהמשתמש מקלידים שאילתות, מתבצעת קריאה לבקשה להשלמה אוטומטית אחרי כל כמה הקשות (לא לכל תו) והמערכת מחזירה רשימה של תוצאות אפשריות.
כשהמשתמש בוחר מתוך רשימת התוצאות, הבחירה נספרת כבקשה, וכל הבקשות שנשלחות במהלך החיפוש מקובצות ונספרות כבקשה אחת. אם המשתמש בוחר מקום, שאילתת החיפוש זמינה ללא תשלום, ורק הבקשה לנתוני המקום מחויבת. אם המשתמש לא מבצע בחירה תוך כמה דקות מתחילת הסשן, מתבצע חיוב רק על שאילתה החיפוש.
נבחן את תהליך האירועים הזה מנקודת המבט של אפליקציה.
משתמש מתחיל להקליד שאילתה לחיפוש 'פריז, צרפת'.
כשהאפליקציה מזהה קלט של משתמש, היא יוצרת אסימון סשן חדש, 'אסימון א'.
כשהמשתמש מקלידים, ה-API שולח בקשה להשלמה אוטומטית אחרי כל כמה תווים, ומציג רשימה חדשה של תוצאות אפשריות לכל אחד מהם:
"P"
"Par"
"Paris,"
"Paris, Fr"
כשהמשתמש מבצע בחירה:
כל הבקשות שמתקבלות מהשאילתה מקובצות ומתווספות לסשן שמיוצג על ידי אסימון א', כבקשה אחת.
הבחירה של המשתמש נספרת כבקשה לפרטים של מקום, ומתווספת לסשן שמיוצג על ידי אסימון א'.
הסשן מסתיים והאפליקציה משליכה את אסימון א'.
למידע נוסף על החיוב על בקשות להשלמה אוטומטית של מקומות (מדור קודם), קראו את המאמר שימוש וחיוב.
יצירת אסימוני סשן
אפשר ליצור אסימוני סשן באמצעות כל מנגנון פרוגרמטי שתרצו. מומלץ להשתמש ב-UUID מגרסה 4 לאסימוני סשן.
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-09-04 (שעון UTC)."],[],[],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/web-service/usage-and-billing#about-autocomplete-sessions).\n\nCreate session tokens\n---------------------\n\n\nYou can create session tokens using whichever programmatic mechanism you\nprefer. We recommend using a [version 4 UUID](https://tools.ietf.org/html/rfc4122)\nfor session tokens."]]