โทเค็นของเซสชัน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Place Autocomplete (เดิม) ใช้โทเค็นเซสชันเพื่อจัดกลุ่มระยะการค้นหาและการเลือกของผู้ใช้ที่เติมข้อความอัตโนมัติไว้ในเซสชันแยกต่างหากเพื่อวัตถุประสงค์ในการเรียกเก็บเงิน เซสชันจะเริ่มขึ้นเมื่อผู้ใช้เริ่มพิมพ์ข้อความค้นหา และสิ้นสุดลงเมื่อผู้ใช้เลือกสถานที่และมีการเรียกใช้รายละเอียดสถานที่ (เดิม) เซสชันแต่ละรายการอาจมีคำค้นหาที่เติมข้อความอัตโนมัติหลายรายการตามด้วยการเลือกสถานที่ 1 แห่ง คีย์ API ที่ใช้สำหรับคำขอแต่ละรายการภายในเซสชันต้องอยู่ในโปรเจ็กต์คอนโซล Google Cloud เดียวกัน เมื่อเซสชันสิ้นสุดลง โทเค็นจะใช้งานไม่ได้อีกต่อไป แอปของคุณจึงต้องสร้างโทเค็นใหม่สำหรับแต่ละเซสชัน หากไม่ระบุพารามิเตอร์ sessiontoken
หรือคุณใช้โทเค็นเซสชันซ้ำ ระบบจะเรียกเก็บเงินสำหรับเซสชันราวกับว่าไม่มีการระบุโทเค็นเซสชัน (ระบบจะเรียกเก็บเงินสำหรับคำขอแต่ละรายการแยกกัน)
เราขอแนะนำให้ทำตามหลักเกณฑ์ต่อไปนี้
- ใช้โทเค็นเซสชันสำหรับเซสชันการป้อนข้อความอัตโนมัติทั้งหมด
- สร้างโทเค็นใหม่สำหรับแต่ละเซสชัน
- ตรวจสอบว่าคีย์ API ที่ใช้สำหรับคำขอการเติมข้อความอัตโนมัติของสถานที่ (เดิม) และรายละเอียดสถานที่ (เดิม) ทั้งหมดภายในเซสชันเป็นของโปรเจ็กต์คอนโซล Google Cloud เดียวกัน
- อย่าลืมส่งโทเค็นเซสชันที่ไม่ซ้ำกันสำหรับเซสชันใหม่แต่ละรายการ การใช้โทเค็นเดียวกันในเซสชันมากกว่า 1 รายการจะทำให้มีการเรียกเก็บเงินสำหรับคำขอแต่ละรายการแยกกัน
คุณเลือกที่จะไม่ใส่โทเค็นเซสชันการเติมข้อความอัตโนมัติในคำขอได้ หากไม่ได้ระบุโทเค็นเซสชัน ระบบจะเรียกเก็บเงินสำหรับคำขอแต่ละรายการแยกกัน ซึ่งจะทริกเกอร์ SKU Autocomplete - Per Request
หากคุณใช้โทเค็นเซสชันซ้ำ ระบบจะถือว่าเซสชันไม่ถูกต้องและจะเรียกเก็บเงินสำหรับคำขอราวกับว่าไม่มีการระบุโทเค็นเซสชัน
ตัวอย่าง
ขณะที่ผู้ใช้พิมพ์ข้อความ ระบบจะเรียกใช้คําขอเติมข้อความอัตโนมัติทุกๆ 2-3 การกดแป้นพิมพ์ (ไม่ใช่ต่ออักขระ) และแสดงรายการผลลัพธ์ที่เป็นไปได้
เมื่อผู้ใช้เลือกจากรายการผลลัพธ์ การเลือกดังกล่าวจะนับเป็นคําขอ และระบบจะรวมคําขอทั้งหมดที่ส่งระหว่างการค้นหาไว้ด้วยกันและนับเป็นคําขอเดียว หากผู้ใช้เลือกสถานที่ คำค้นหาจะใช้งานได้โดยไม่มีค่าใช้จ่าย และระบบจะเรียกเก็บเงินเฉพาะคำขอข้อมูลสถานที่เท่านั้น หากผู้ใช้ไม่เลือกภายในไม่กี่นาทีหลังจากเริ่มเซสชัน ระบบจะเรียกเก็บเงินเฉพาะคำค้นหา
มาวิเคราะห์ลําดับเหตุการณ์นี้จากมุมมองของแอปกัน
- ผู้ใช้เริ่มพิมพ์ข้อความค้นหาเพื่อค้นหา "ปารีส ฝรั่งเศส"
- เมื่อตรวจพบอินพุตของผู้ใช้ แอปจะสร้างโทเค็นเซสชันใหม่ "โทเค็น ก"
- ขณะที่ผู้ใช้พิมพ์ API จะส่งคําขอเติมข้อความอัตโนมัติทุกๆ 2-3 อักขระ โดยแสดงรายการผลลัพธ์ที่เป็นไปได้ใหม่สำหรับแต่ละรายการ
"P"
"Par"
"Paris,"
"Paris, Fr"
- เมื่อผู้ใช้เลือกตัวเลือก ระบบจะดำเนินการดังนี้
- ระบบจะจัดกลุ่มคำขอทั้งหมดที่เกิดจากการค้นหาและเพิ่มลงในเซสชันที่แสดงโดย "โทเค็น ก" เป็นคำขอเดียว
- ระบบจะนับการเลือกของผู้ใช้เป็นคําขอรายละเอียดสถานที่ และเพิ่มลงในเซสชันที่แสดงโดย "โทเค็น ก"
- เซสชันสิ้นสุดลงและแอปทิ้ง "โทเค็น ก"
ดูข้อมูลเพิ่มเติมเกี่ยวกับการเรียกเก็บเงินสำหรับคำขอการเติมข้อความอัตโนมัติของสถานที่ (เดิม) ได้ที่การใช้งานและการเรียกเก็บเงิน
สร้างโทเค็นเซสชัน
คุณสามารถสร้างโทเค็นเซสชันได้โดยใช้กลไกแบบเป็นโปรแกรมใดก็ได้ที่ต้องการ เราขอแนะนำให้ใช้ UUID เวอร์ชัน 4 สำหรับโทเค็นเซสชัน
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 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."]]