Geocoding API は、認証に OAuth 2.0 の使用をサポートしています。Google は、ウェブサーバーなど、OAuth 2.0 の一般的なシナリオに対応しています。
このドキュメントでは、開発環境で Geocoding API 呼び出しに OAuth トークンを渡す方法について説明します。本番環境で OAuth を使用する手順については、Google での認証をご覧ください。
始める前に
Geocoding API を使用するには、請求先アカウントが登録されたプロジェクトを用意し、Geocoding API を有効化しておく必要があります。複数のプロジェクト オーナーと課金管理者を作成し、これらの役割をチーム内の誰かが必ず担えるようにすることをおすすめします。詳しくは、Google Cloud Console でセットアップするをご覧ください。
OAuth について
デプロイ環境に応じて、OAuth でアクセス トークンを作成して管理する方法はいくつかあります。
たとえば、Google OAuth 2.0 システムは、アプリケーションと Google サービス間のサーバー間インタラクションをサポートしています。このシナリオでは、サービス アカウントが必要です。サービス アカウントは、個々のエンドユーザーではなく、アプリケーションに属するアカウントです。サービス アカウントの代わりにアプリケーションによって Google API が呼び出されるため、ユーザーが直接関与することはありません。認証方法の詳細については、Google での認証をご覧ください。
または、Android または iOS モバイルアプリの一部として Geocoding API を使用することもできます。Geocoding API で OAuth を使用する際の一般的な情報(さまざまなデプロイ環境のアクセス トークンの管理など)については、OAuth 2.0 を使用して Google API にアクセスするをご覧ください。
OAuth スコープについて
Geocoding API で OAuth を使用するには、OAuth トークンに正しいスコープを割り当てる必要があります。Geocoding API は次のスコープをサポートしています。
https://www.googleapis.com/auth/maps-platform.geocode
- すべての Geocoding API エンドポイントで使用します。
[[["わかりやすい","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,["# Use OAuth\n\n**European Economic Area (EEA) developers** If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](/maps/comms/eea/faq).\n\nGeocoding API supports the use of OAuth 2.0 for authentication.\nGoogle supports common OAuth 2.0 scenarios such as those for a web server.\n\nThis document describes how to pass an OAuth token to the Geocoding API call in your\n**development** environment. For instructions on using OAuth in a\n**production** environment, see\n[Authentication at Google](https://cloud.google.com/docs/authentication).\n| **Note:** While you can use Google Maps APIs directly by making API requests to the server, [client libraries](https://cloud.google.com/apis/docs/client-libraries-explained) provide simplifications that significantly reduce the amount of code you need to write. Google Maps provides client libraries for many programming languages, including Go, Java, Node.js, and Python.\n|\n| \u003cbr /\u003e\n|\n| See [Geocoding API Client Libraries](/maps/documentation/geocoding/client_libraries) for\n| documentation and examples.\n\nBefore you begin\n----------------\n\nBefore you start using the Geocoding API, you need a\nproject with a billing account and the Geocoding API enabled. We recommend creating multiple\nProject Owners and Billing Administrators, so that you'll always have someone with these roles\navailable to your team. To learn more, see [Set up in Cloud Console](/maps/documentation/geocoding/cloud-setup).\n\nAbout OAuth\n-----------\n\nThere are many ways to create and manage access tokens with OAuth based on your deployment\nenvironment.\n\nFor example, the Google OAuth 2.0 system supports server-to-server interactions, such as those\nbetween your application and a Google service. For this scenario you need a service account, which\nis an account that belongs to your application instead of to an individual end user. Your\napplication calls Google APIs on behalf of the service account, so users aren't directly involved.\nFor more information on authentication methods, see\n[Authentication at Google](https://cloud.google.com/docs/authentication).\n\nAlternatively, you might use the Geocoding API as part of an Android or iOS mobile app.\nFor general information on using OAuth with the Geocoding API, including information on managing\naccess tokens for different deployment environments, see\n[Using OAuth 2.0 to Access Google APIs](/identity/protocols/oauth2).\n\nAbout OAuth scopes\n------------------\n\nTo use OAuth with the Geocoding API, the OAuth token must be assigned the correct scope. Geocoding API supports the following scopes:\n\n- `https://www.googleapis.com/auth/maps-platform.geocode` --- Use with all Geocoding API endpoints.\n- `https://www.googleapis.com/auth/maps-platform.geocode.address` --- Use only with `GeocodeAddress` for forward geocoding.\n- `https://www.googleapis.com/auth/maps-platform.geocode.location` --- Use only with `GeocodeLocation` for reverse geocoding.\n- `https://www.googleapis.com/auth/maps-platform.geocode.place` --- Use only with `GeocodePlace` for place geocoding.\n\nAlso, you can use the general `https://www.googleapis.com/auth/cloud-platform`\nscope for all Geocoding API endpoints. That scope is useful during development\nbecause it is the default scope used when creating tokens using\n`gcloud`.\n\n\nExample: Try REST API calls in your local development environment\n-----------------------------------------------------------------\n\nIf you want to try the Geocoding API using an OAuth token, but do not have an environment\nsetup to generate tokens, you can use the procedure in this section to make the call.\n\nThis example describes how to use the OAuth token provided by\n[Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials)\nto make the call. For information about using ADC to call Google APIs using client libraries, see\n[Authenticate using client libraries](https://cloud.google.com/docs/authentication/client-libraries).\n| **Note**: The procedure below to make a REST call is not intended for use in a production environment. Use this procedure for a development or testing environment only.\n\n### Prerequisites\n\nBefore you can make a REST request using ADC, use the Google Cloud CLI\nto provide credentials to ADC:\n\n1. If you haven't already, create a project and enable billing by following the steps in the [Set Up in the Google Cloud Console](/maps/documentation/geocoding/cloud-setup).\n2. [Install and initialize the gcloud CLI](https://cloud.google.com/sdk/docs/install?utm_source=Docs_InstallGcloud&utm_content=Docs_geocoding-backend).\n3. Run the following `gcloud` command on your local machine to create your\n credential file:\n\n ```\n gcloud auth application-default login\n ```\n4. A login screen is displayed. After you log in, your credentials are stored in the [local credential file used by ADC](https://cloud.google.com/docs/authentication/application-default-credentials#personal).\n\nFor more information, see\n[Local development environment](https://cloud.google.com/docs/authentication/provide-credentials-adc#local-dev)\nsection of the\n[Provide credentials for Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc)\ndocumentation.\n\n### Make a REST request\n\nIn this example, you pass two request headers:\n\n- Pass the OAuth token in the `Authorization` header by using the following\n command to generate the token:\n\n [gcloud auth application-default print-access-token](https://cloud.google.com/sdk/gcloud/reference/auth/application-default/print-access-token)\n\n The returned token has a scope of\n `https://www.googleapis.com/auth/cloud-platform.`\n- Pass the ID or name of your Google Cloud project that has billing enabled in the `X-Goog-User-Project` header. To learn more, see [Set up in Cloud Console](/maps/documentation/geocoding/cloud-setup).\n\nThe following example makes a call to the Geocoding API using an OAuth token: \n\n```json\ncurl -X GET -H 'Content-Type: application/json' \\\n-H \"Authorization: Bearer $(gcloud auth application-default print-access-token)\" \\\n-H \"X-Goog-User-Project: PROJECT_ID\" \\\n\"https://geocode.googleapis.com/v4beta/geocode/address/1600+Amphitheatre+Parkway,+Mountain+View,+CA\"\n```\n\n\n### Troubleshooting\n\nIf your request returns an error message about end-user credentials not being supported by this API,\nsee [User credentials not working](https://cloud.google.com/docs/authentication/provide-credentials-adc#user-creds-client-based)."]]