Geocoding API รองรับการใช้ OAuth 2.0 สำหรับการตรวจสอบสิทธิ์
Google รองรับสถานการณ์ทั่วไปของ OAuth 2.0 เช่น สำหรับเว็บเซิร์ฟเวอร์
เอกสารนี้อธิบายวิธีส่งโทเค็น OAuth ไปยังการเรียก Geocoding API ในสภาพแวดล้อมการพัฒนา ดูวิธีการใช้ OAuth ในสภาพแวดล้อมเวอร์ชันที่ใช้งานจริงได้ที่การตรวจสอบสิทธิ์ที่ Google
ก่อนเริ่มต้น
ก่อนเริ่มใช้ Geocoding API คุณต้องมีโปรเจ็กต์ที่มีบัญชีการเรียกเก็บเงินและเปิดใช้ Geocoding API เราขอแนะนำให้สร้างเจ้าของโปรเจ็กต์และผู้ดูแลการเรียกเก็บเงินหลายคน เพื่อให้คุณมีบุคคลที่มีบทบาทเหล่านี้ให้ทีมของคุณใช้งานเสมอ ดูข้อมูลเพิ่มเติมได้ที่ตั้งค่าใน Cloud Console
ตัวอย่างเช่น ระบบ OAuth 2.0 ของ Google รองรับการโต้ตอบระหว่างเซิร์ฟเวอร์ เช่น การโต้ตอบระหว่างแอปพลิเคชันของคุณกับบริการของ Google ในกรณีนี้ คุณต้องมีบัญชีบริการ ซึ่งเป็นบัญชีของแอปพลิเคชันคุณ ไม่ใช่ของผู้ใช้ปลายทางแต่ละราย แอปพลิเคชันจะเรียกใช้ Google APIs ในนามบัญชีบริการนั้น ผู้ใช้จึงไม่มีส่วนเกี่ยวข้องโดยตรง
ดูข้อมูลเพิ่มเติมเกี่ยวกับวิธีการตรวจสอบสิทธิ์ได้ที่การตรวจสอบสิทธิ์ที่ Google
หรือคุณอาจใช้ Geocoding API เป็นส่วนหนึ่งของแอปบนอุปกรณ์เคลื่อนที่ Android หรือ iOS ก็ได้ โปรดดูข้อมูลทั่วไปเกี่ยวกับการใช้ OAuth กับ Geocoding API รวมถึงข้อมูลเกี่ยวกับการจัดการโทเค็นการเข้าถึงสําหรับสภาพแวดล้อมการติดตั้งใช้งานต่างๆ ที่หัวข้อการใช้ OAuth 2.0 เพื่อเข้าถึง Google API
เกี่ยวกับขอบเขต OAuth
หากต้องการใช้ OAuth กับ Geocoding API คุณต้องกำหนดขอบเขตที่ถูกต้องให้กับโทเค็น 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)."]]