このプロダクトまたは機能は、従来版のステータスです。従来版のステータスの詳細については、
従来版のサービスと機能をご覧ください。Places API(新規)に移行するには、
移行ガイドをご覧ください。
セッション トークン
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Place Autocomplete(従来版)は、セッション トークンを使用して、ユーザーの予測入力検索のクエリと選択フェーズを、請求処理のために個別のセッションにグループ化します。セッションは、ユーザーが検索語句を入力し始めたときに開始され、ユーザーが場所を選択し、Place Details(従来版)が呼び出されると終了します。セッションによっては、複数の自動入力クエリが入力された後に、1 つの場所が選択される場合もあります。セッション内の各リクエストに使用する API キーは、同じ Google Cloud コンソール プロジェクトに属している必要があります。セッションが終了すると、トークンは無効になります。アプリでは、セッションごとに新しいトークンを生成する必要があります。sessiontoken
パラメータを省略する場合や、セッション トークンを再利用する場合は、セッション トークンが指定されていない場合と同様にセッションが課金されます(各リクエストが個別に課金されます)。
次のガイドラインに従うことをおすすめします。
- すべての予測入力セッションでセッション トークンを使用します。
- セッションごとに新しいトークンを生成します。
- セッション内のすべての Place Autocomplete(従来版)リクエストと Place Details(従来版)リクエストに使用される API キーが、同じ Google Cloud コンソール プロジェクトに属していることを確認します。
- 新しいセッションごとに固有のセッション トークンを渡すようにしてください。複数のセッションで同じトークンを使用すると、リクエストごとに課金されます。
必要に応じて、リクエストから予測入力セッション トークンを省略できます。セッション トークンを省略すると、Autocomplete - Per Request SKU がトリガーされ、各リクエストが個別に課金されます。セッション トークンを再使用すると、そのセッションは無効とみなされ、セッション トークンを渡さなかった場合と同様にリクエストが課金されます。
例
ユーザーがクエリを入力すると、キーを数回打つごとに(1 文字ずつではなく)予測入力リクエストが呼び出され、候補のリストが返されます。
ユーザーが結果リストから選択を行うと、その選択がリクエストとしてカウントされ、検索中に行われたすべてのリクエストがバンドルされて 1 つのリクエストとしてカウントされます。ユーザーが場所を選択すると、その検索クエリは料金なしで利用できます。料金が発生するのは、場所データ リクエストのみです。セッションの開始から数分以内にユーザーが選択を行わなかった場合は、検索クエリのみが課金されます。
では、このイベントフローをアプリの観点から見てみましょう。
- ユーザーがクエリの入力を開始し、「Paris, France」を検索します。
- アプリはユーザー入力を検出すると、新しいセッション トークン「トークン A」を作成します。
- ユーザーが入力を始めると、API が数文字ごとに予測入力リクエストを実行し、各々に新しい候補結果のリストを表示します。
"P"
"Par"
"Paris,"
"Paris, Fr"
- ユーザーが選択を行うと:
- このクエリによるすべてのリクエストはグループ化され、「トークン A」で表されるセッションに 1 つのリクエストとして追加されます。
- ユーザーの選択は Place Detail リクエストとしてカウントされ、「トークン A」で表されるセッションに追加されます。
- セッションが終了し、アプリは「トークン A」を破棄します。
Place Autocomplete(従来版)リクエストに対する課金方法については、使用量と課金をご覧ください。
セッション トークンを作成する
セッション トークンは、任意のプログラマティック メカニズムを使用して作成できます。セッション トークンには バージョン 4 の UUID を使用することをおすすめします。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 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."]]