คุณกำลังดูเอกสารประกอบเดิมสำหรับ Google Photos Library API
เริ่มต้นใช้งาน REST
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ในการเริ่มใช้ API คลังภาพของ Google Photos ให้กำหนดค่าโปรเจ็กต์โดยเปิดใช้ API ผ่าน
คอนโซล Google API และตั้งค่ารหัสไคลเอ็นต์ OAuth 2.0
แอปพลิเคชันของคุณโต้ตอบกับ Google Photos ในนามของ
ผู้ใช้ Google Photos เช่น เมื่อคุณสร้างอัลบั้มใน
คลังภาพ Google Photos หรืออัปโหลดรายการสื่อไปยัง
บัญชี Google Photos ให้ผู้ใช้ให้สิทธิ์คำขอ API เหล่านี้ผ่าน
โปรโตคอล OAuth 2.0
รหัสไคลเอ็นต์ OAuth 2.0 ช่วยให้ผู้ใช้แอปพลิเคชันลงชื่อเข้าใช้ ตรวจสอบสิทธิ์
และนั่นก็คือการใช้ Library API Library API ไม่รองรับ
บัญชีบริการ หากต้องการใช้ API นี้ ผู้ใช้ต้องลงชื่อเข้าใช้บัญชี
บัญชี
เปิดใช้ API
ก่อนที่จะใช้ Library API ได้ คุณต้องเปิดใช้ API สำหรับโปรเจ็กต์ก่อน
- ไปที่คอนโซล Google API
- จากแถบเมนู ให้เลือกโปรเจ็กต์หรือสร้างโปรเจ็กต์ใหม่
- หากต้องการเปิดไลบรารี Google API จากเมนูการนำทาง ให้เลือก
API และ บริการ > คลัง
- ค้นหา "Google Photos Library API" เลือกผลลัพธ์ที่ถูกต้องและคลิก
เปิดใช้
ขอรหัสไคลเอ็นต์ OAuth 2.0
ทําตามขั้นตอนด้านล่างเพื่อขอรหัสไคลเอ็นต์ OAuth และกําหนดค่าให้กับ
แอปพลิเคชัน ตัวอย่างนี้ใช้แอปพลิเคชันที่ขั้นตอน OAuth ทั้งหมด
ฝั่งเซิร์ฟเวอร์ที่จัดการ อย่างเช่นในตัวอย่างของเรา ขั้นตอนการตั้งค่าอาจแตกต่างกันไป
เพื่อดูสถานการณ์การใช้งานอื่นๆ
- ไปที่คอนโซล Google API
แล้วเลือกโปรเจ็กต์
- จากเมนู ให้เลือก API & บริการ > ข้อมูลเข้าสู่ระบบ
- ในหน้าข้อมูลเข้าสู่ระบบ ให้คลิกสร้างข้อมูลเข้าสู่ระบบ > รหัสไคลเอ็นต์ OAuth
- เลือกประเภทแอปพลิเคชัน ในตัวอย่างนี้ ประเภทแอปพลิเคชันคือ
เว็บแอปพลิเคชัน
ลงทะเบียนต้นทางที่แอปของคุณได้รับอนุญาตให้เข้าถึง Google APIs
ดังนี้
- หากต้องการระบุรหัสไคลเอ็นต์ ให้ป้อนชื่อ
ในช่องต้นทาง JavaScript ที่ได้รับอนุญาต ให้ป้อนต้นทาง
แอป ช่องนี้ไม่อนุญาตให้ใช้ไวลด์การ์ด
คุณป้อนต้นทางหลายแห่งได้เพื่อให้แอปทำงานบน
โปรโตคอล โดเมน หรือโดเมนย่อย URL ที่คุณป้อนได้รับอนุญาตให้
เริ่มคำขอ OAuth
ตัวอย่างต่อไปนี้แสดง URL การพัฒนาในเครื่อง (ตัวอย่างของเราใช้
localhost:8080
) และ URL เวอร์ชันที่ใช้งานจริง
http://localhost:8080
https://myproductionurl.example.com
ช่อง URL การเปลี่ยนเส้นทางที่ได้รับอนุญาตคือปลายทางที่รับ
การตอบกลับจากเซิร์ฟเวอร์ OAuth 2.0 โดยทั่วไป กรณีนี้จะรวมถึง
การพัฒนาซอฟต์แวร์และชี้ไปยังเส้นทางในแอปพลิเคชันของคุณ
http://localhost:8080/auth/google/callback
https://myproductionurl.example.com/auth/google/callback
คลิกสร้าง
-
คัดลอกข้อมูลต่อไปนี้จากกล่องโต้ตอบไคลเอ็นต์ OAuth ที่ได้
- Client-ID
- รหัสลับไคลเอ็นต์
แอปของคุณเข้าถึง Google API ที่เปิดใช้ได้โดยใช้ค่าเหล่านี้
ก่อนที่คุณจะสามารถเปิดแอปพลิเคชันสาธารณะที่เข้าถึง Library API ได้
แอปของคุณต้องได้รับการตรวจสอบจาก Google "แอปที่ไม่ได้รับการยืนยัน" ปรากฏใน
เมื่อคุณทดสอบแอปพลิเคชัน จนกว่าจะ
ได้รับการยืนยันแล้ว
ดูตัวอย่าง
เมื่อคุณกำหนดค่าโปรเจ็กต์สำหรับใช้กับ Library API แล้ว
ดูแอปตัวอย่างใน GitHub แอปตัวอย่าง
สาธิตวิธีสร้างกรอบรูปอัจฉริยะโดยใช้ Library API
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-29 UTC
[null,null,["อัปเดตล่าสุด 2025-08-29 UTC"],[[["\u003cp\u003eTo use the Google Photos Library API, you must enable the API and set up an OAuth 2.0 client ID through the Google API Console.\u003c/p\u003e\n"],["\u003cp\u003eUsers must be signed in to a valid Google Account to use the Library API as it requires user authorization via OAuth 2.0 for actions like creating albums or uploading media.\u003c/p\u003e\n"],["\u003cp\u003eBefore launching publicly, your application needs to be reviewed and verified by Google to remove the "Unverified app" message during testing.\u003c/p\u003e\n"]]],["To utilize the Google Photos Library API, first enable it for your project in the Google API Console. Then, create an OAuth 2.0 client ID, specifying the application type, authorized JavaScript origins, and redirect URIs. Obtain the client ID and secret from the resulting dialog. Ensure your application is reviewed by Google before public launch. Note, only valid Google Account users can use this API as service accounts aren't supported.\n"],null,["# Get started with REST\n\nTo start using the Google Photos Library API, configure your project by enabling the API via\nthe Google API Console and setting up an OAuth 2.0 client ID.\n\nYour application interacts with Google Photos on behalf of a\nGoogle Photos user. For instance, when you create albums in a user's\nGoogle Photos library or upload media items to a user's\nGoogle Photos account, the user authorizes these API requests via the\n[OAuth 2.0](/identity/protocols/OAuth2) protocol.\n\nThe OAuth 2.0 client ID allows your application users to sign in, authenticate,\nand thereby use the Library API. The Library API does not support\nservice accounts; to use this API, users must be signed in to a valid Google\nAccount.\n\nConfigure your app\n------------------\n\n### Enable the API\n\nBefore you can use the Library API, you must enable it for your project.\n\n1. Go to the [Google API Console](https://console.developers.google.com/apis/library).\n2. From the menu bar, select a project or create a new project.\n3. To open the Google API Library, from the Navigation menu, select **APIs \\& Services \\\u003e Library**.\n4. Search for \"Google Photos Library API\". Select the correct result and click **Enable**.\n\n### Request an OAuth 2.0 client ID\n\nFollow the steps below to request an OAuth client ID and configure it for your\napplication. This example uses an application where the entire OAuth flow is\nhandled server-side, such as the one in our samples. The setup process may vary\nfor other [implementation scenarios](/identity/protocols/OAuth2).\n\n1. Go to the [Google API Console](https://console.developers.google.com/apis/library) and select your project.\n2. From the menu, select **APIs \\& Services \\\u003e Credentials**.\n3. On the **Credentials** page, click **Create Credentials \\\u003e OAuth client ID**.\n4. Select your **Application type** . In this example, the application type is **Web application**.\n5. Register the origins from which your app is allowed to access the Google APIs\n as follows:\n\n 1. To identify the client ID, enter a name.\n 2. In the **Authorized JavaScript origins** field, enter the origin for your\n app. This field doesn't allow wildcards.\n\n You can enter multiple origins to allow your app to run on different\n protocols, domains, or subdomains. The URLs you enter are allowed to\n start an OAuth request.\n\n The following example shows a local development URL (our samples use\n `localhost:8080`) and a production URL. \n\n http://localhost:8080\n https://myproductionurl.example.com\n\n 3. The **Authorized redirect URI** field is the endpoint that receives\n responses from the OAuth 2.0 server. Typically, this includes your\n development environment and points to a path in your application.\n\n http://localhost:8080/auth/google/callback\n https://myproductionurl.example.com/auth/google/callback\n\n 4. Click **Create**.\n\n\u003c!-- --\u003e\n\n6. From the resulting OAuth client dialog, copy the following:\n\n - Client ID\n - Client secret\n\n Your app can access the enabled Google APIs using these values.\n\nBefore you can launch a public application that accesses the Library API,\nyour app must be reviewed by Google. An \"Unverified app\" message appears on the\nscreen when you test your application, until it is\n[verified](https://support.google.com/cloud/answer/7454865).\n\nTry out the sample\n------------------\n\nNow that you've configured your project for use with the Library API,\ncheck out the [sample app](/photos/library/samples) on GitHub. The sample app\ndemonstrates how you can build a smart photo frame using the Library API."]]