กำลังสร้างข้อมูลเข้าสู่ระบบการตรวจสอบสิทธิ์ REST API ของ Google Wallet
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Google Wallet มี REST API ที่ให้คุณสร้างและจัดการบัตรด้วยการส่งคำขอไปยัง Google Wallet API ผ่าน HTTP ซึ่งจะเป็นประโยชน์สำหรับผู้ที่ต้องการสร้างบริการฝั่งเซิร์ฟเวอร์เพื่อทำงานกับบัตรแบบเป็นโปรแกรม
หากต้องการใช้ Google Wallet REST API คุณต้องเปิดใช้ API ในคอนโซล Google Cloud สร้างบัญชีบริการ Google Cloud แล้วสร้างคีย์สำหรับบัญชีบริการ
เมื่อสร้างบัตรด้วย REST API คีย์บัญชีบริการที่ใช้ในการลงนามออบเจ็กต์ Passes ที่เข้ารหัสด้วยโทเค็นเว็บ JSON
สำหรับการดำเนินการอื่นๆ เช่น การอัปเดตหรือลบบัตร ระบบจะส่งคีย์บัญชีบริการไปพร้อมกับคำขอเพื่อตรวจสอบสิทธิ์ของคุณในฐานะผู้ออกบัตร
1. เปิดใช้ Google Wallet REST API
หากต้องการเปิดใช้ Google Wallet REST API ให้ทำดังนี้
- หากยังไม่มีบัญชี Google Cloud ให้ไปที่คอนโซล Google Cloud แล้วทำตามขั้นตอนเพื่อลงทะเบียนบัญชีใหม่
- จากเมนูแบบเลื่อนลงของโปรเจ็กต์ที่ด้านบนของคอนโซล ให้เลือกโปรเจ็กต์ Google Cloud ที่ต้องการใช้หรือสร้างโปรเจ็กต์ใหม่
- ไปที่หน้ารายละเอียดผลิตภัณฑ์ Google Wallet API ใน Google Cloud Console Marketplace
- คลิกปุ่ม "เปิดใช้งาน" ในอีกสักครู่ Google Wallet REST API จะพร้อมใช้งานสำหรับโปรเจ็กต์ Google Cloud ที่เลือก
2. สร้างคีย์บัญชีบริการ Google Cloud
ในการตรวจสอบสิทธิ์คำขอที่ส่งไปยัง Google Wallet REST API คุณจะต้องสร้างบัญชีบริการและสร้างคีย์บัญชีบริการโดยทำตามขั้นตอนต่อไปนี้
- ไปที่หน้า "สร้างบัญชีบริการ" ในคอนโซล Google Cloud
- กรอกรายละเอียดบัญชีบริการ จดที่อยู่อีเมลสำหรับบัญชีบริการ
ที่ปรากฏใต้ช่อง "รหัสบัญชีบริการ" คุณจะต้องใช้บัญชีนี้ในภายหลังเมื่อใช้บัญชีบริการเพื่อตรวจสอบสิทธิ์คำขอที่ส่งไปยัง Google Wallet REST API
- คลิกปุ่ม 'เสร็จสิ้น' คุณไม่จำเป็นต้องดำเนินการตามขั้นตอนการสร้างบัญชีบริการอื่นให้เสร็จสมบูรณ์
- คลิกรายการในเมนู "คีย์" ที่ด้านบนของหน้า
- คลิกเมนูแบบเลื่อนลง "เพิ่มคีย์" จากนั้นคลิก "สร้างคีย์ใหม่"
- เลือกประเภทคีย์ "JSON"
- คลิก "สร้าง" เพื่อสร้างและดาวน์โหลดคีย์บัญชีบริการ
3. ให้สิทธิ์บัญชีบริการในคอนโซล Google Wallet
หากต้องการตรวจสอบสิทธิ์คำขอที่ส่งไปยัง Google Wallet REST API โดยใช้คีย์บัญชีบริการ คุณต้องเพิ่มอีเมลของบัญชีบริการเป็นผู้ใช้ในบัญชีผู้ออกบัตร หากต้องการเพิ่มบัญชีบริการเป็นผู้ใช้ ให้ทำดังนี้
- ไปที่หน้า "บัญชีบริการ" ในคอนโซล Google Cloud
- คัดลอกอีเมลของบัญชีบริการที่ต้องการใช้เพื่อตรวจสอบสิทธิ์คำขอที่ส่งไปยัง Google Wallet API
- ไปที่คอนโซล Google Pay และ Wallet
- ในเมนูการนำทางด้านซ้าย คลิก "ผู้ใช้"
- คลิก "เชิญผู้ใช้"
- ป้อนอีเมลของบัญชีบริการ
- ในรายการแบบเลื่อนลง "ระดับการเข้าถึง" ให้เลือก "นักพัฒนาซอฟต์แวร์"
- คลิกปุ่ม "เชิญ"
เมื่อเพิ่มบัญชีบริการแล้ว คุณจะใช้คีย์บัญชีบริการใดก็ได้ที่สร้างขึ้นเพื่อตรวจสอบสิทธิ์คำขอที่ส่งไปยัง Google Wallet REST API เมื่อใช้คีย์บัญชีบริการ โปรดทราบว่าคีย์บัญชีบริการเหล่านี้เป็นข้อมูลเข้าสู่ระบบที่มีความละเอียดอ่อนสูง และควรใช้ในสภาพแวดล้อมฝั่งเซิร์ฟเวอร์ที่ปลอดภัยเท่านั้น
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-29 UTC
[null,null,["อัปเดตล่าสุด 2025-08-29 UTC"],[[["\u003cp\u003eGoogle Wallet's REST API enables programmatic management of passes through HTTP requests, ideal for server-side integrations.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize the API, you must enable it in the Google Cloud console, create a Google Cloud service account, and generate a key for authentication.\u003c/p\u003e\n"],["\u003cp\u003eThe service account key is crucial for signing JSON Web Token-encoded Passes Objects during pass creation and authenticating other operations like updates or deletions.\u003c/p\u003e\n"],["\u003cp\u003eBefore using the API, authorize your service account by adding its email address as a Developer user in the Google Pay & Wallet console.\u003c/p\u003e\n"]]],["The Google Wallet REST API allows programmatic pass management via HTTP requests. To use it, enable the API in the Google Cloud console, create a service account, and generate a JSON key. This key is used to sign JSON Web Token-encoded Pass Objects for creation and authenticates requests for updates or deletions. Finally, authorize the service account by adding its email as a 'Developer' user in the Google Pay & Wallet console. This process enables secure, server-side interaction with the Google Wallet.\n"],null,["# Generating Google Wallet REST API authentication credentials\n\nGoogle Wallet offers a REST API that lets you create and manage passes by\nsending requests to the Google Wallet API over HTTP. This is useful for those who\nwant to build server-side services to work with passes programmatically.\n\nTo use the Google Wallet REST API, you must enable the API in the Google Cloud console,\ncreate a Google Cloud service account, then generate a key for the service account.\n\nWhen you create passes with the REST API, the service account key used to sign your\nJSON Web Token-encoded Passes Objects.\n\nFor other operations, such as updating or deleting passes, the service account key\nis sent with the request to authenticate you as the Pass Issuer.\n\n1. Enable the Google Wallet REST API\n------------------------------------\n\nTo enable the Google Wallet REST API, do the following:\n\n1. If you don't already have a Google Cloud account, go to the [Google Cloud console](https://console.cloud.google.com) and follow the steps to register for a new account.\n2. From the project drop-down menu at the top of the console, select the Google Cloud project you want to use, or create a new one.\n3. Go to the [Google Wallet API product details page](https://console.cloud.google.com/apis/library/walletobjects.googleapis.com) in the Google Cloud console Marketplace.\n4. Click the 'Enable' button. In a few moments, the Google Wallet REST API will be available for the selected Google Cloud project.\n\n2. Generate a Google Cloud service account key\n----------------------------------------------\n\nTo authenticate requests to the Google Wallet REST API, you'll need to create a\nservice account, and generate a service account key by doing the following:\n\n1. Go to the ['Create service account' page](https://console.cloud.google.com/iam-admin/serviceaccounts/create) in the Google Cloud console.\n2. Fill in the service account details. Note the email address for the service account that appears below the 'Service account ID' field. You will need this later when you use the service account to authenticate your requests to the Google Wallet REST API.\n3. Click the 'DONE' button. There is no need to complete the other service account creation steps.\n4. Click the 'KEYS' menu item at the top of the page.\n5. Click the 'ADD KEY' drop-down menu, then click 'Create new key'.\n6. Select key type 'JSON'.\n7. Click 'CREATE' to create and download the service account key.\n\n3. Authorize your service account in the Google Wallet console\n--------------------------------------------------------------\n\nTo authenticate your requests to the Google Wallet REST API using a service account\nkey, you must add the email address of your service account as a user to your\nIssuer account. To add your service account as a user, do the following:\n\n1. Go to the ['Service accounts'](https://console.cloud.google.com/iam-admin/serviceaccounts) page in the Google Cloud console.\n2. Copy the email address of the service account you want to use to authenticate your requests to the Google Wallet API.\n3. Go to the [Google Pay \\& Wallet console](https://pay.google.com/business/console/).\n4. In the left nav, click 'Users'.\n5. Click 'Invite a user'.\n6. Input the email address of your service account.\n7. In the 'Access level' drop-down, select 'Developer'.\n8. Click the 'Invite' button.\n\nOnce your service account is added, you can use any service account keys generated\nfor it to authenticate requests to the Google Wallet REST API. When using service\naccount keys, keep in mind that these are highly sensitive credentials that\nshould only be used in secure, server-side environments."]]