Skip to content

เพิ่มช่องทาง Google Drive

สิ่งที่ต้องเตรียมก่อน

ก่อนเริ่ม ให้เตรียมสิ่งเหล่านี้:

ข้อกำหนดทำไมต้องใช้
Google accountใช้เข้าถึง Google Cloud และ authorize Google Drive
Google Cloud projectใช้ enable Drive API และสร้าง OAuth credentials
OAuth 2.0 clientImgHost ใช้รับ Client ID, Client Secret และ Refresh Token
ImgHost domain ของคุณใช้เป็น OAuth redirect URI ต้องตรงกับ domain ที่ใช้งานจริง

ขั้นตอนตั้งค่า

ขั้นตอนที่ 1: Enable Google Drive API

  1. เปิด Google Cloud Console
  2. สร้าง project ใหม่หรือเลือก project ที่มีอยู่แล้ว
  3. ไปที่ APIs & Services
  4. คลิก Enable APIs and Services
  5. ค้นหา Google Drive API
  6. เปิดแล้วคลิก enable
  1. ใน Google Cloud เปิด Google Auth Platform
  2. กรอกข้อมูลพื้นฐานใน Branding เช่น app name, support email และ developer contact email
  3. เปิด Audience
  4. สำหรับ self-hosted personal deployments ส่วนใหญ่ ให้เลือก External
  5. ถ้าเลือก External ให้เพิ่ม Google account ที่ต้องการ authorize ใน Test users
  6. เปิด Data Access
  7. เพิ่ม Google Drive permissions ที่ต้องใช้

ขั้นตอนที่ 3: สร้าง OAuth 2.0 Client

  1. ใน Google Auth Platform เปิด Clients
  2. สร้าง client ใหม่
  3. ตั้ง application type เป็น Web application
  4. ตั้งชื่อ client ให้จำง่าย
  5. สำหรับ authorized JavaScript origins ให้ใส่ ImgHost URL เช่น:
text
https://img.example.com
  1. สำหรับ authorized redirect URIs ให้ใส่:
text
https://img.example.com/api/oauth/google/callback

สร้าง OAuth client

ใส่ domain และ callback URL

หลังสร้าง client แล้ว ให้คัดลอกค่าเหล่านี้:

ค่าที่สร้างขึ้นฟิลด์ ImgHost
Client IDClient ID
Client SecretClient Secret

ขั้นตอนที่ 4: ใส่ช่องทาง Google Drive

ใน Upload Settings เลือก Google Drive แล้วกรอก:

ฟิลด์ ImgHostใส่อะไร
Channel nameชื่อที่จำง่าย เช่น Main Google Drive
Client IDClient ID จาก Google Cloud
Client SecretClient Secret จาก Google Cloud
Refresh Tokenเว้นว่างไว้ก่อน รับในขั้นตอนถัดไป
Root directoryไม่บังคับ ค่าเริ่มต้นคือ imgbed

กรอกรายละเอียด client ใน ImgHost

ขั้นตอนที่ 5: รับ Refresh Token

  1. คลิก Get Token
  2. เลือก Google account ที่ต้องการเชื่อมต่อ
  3. ทำ authorization prompts ให้เสร็จ
  4. หน้า callback จะแสดง Refresh Token
  5. คัดลอก token นั้น
  6. กลับไปที่ ImgHost แล้ววางในฟิลด์ Refresh Token

คัดลอก Refresh Token หลัง authorization

ถ้าภายหลังเปลี่ยน Google account, เปลี่ยน OAuth client หรือ authorization เก่าหมดอายุ ไม่จำเป็นต้องลบช่องทาง ให้เปิดหน้าแก้ไขแล้วคลิก Reauthorize

ขั้นตอนที่ 6: บันทึกช่องทาง

เมื่อกรอกครบทุกฟิลด์แล้วให้บันทึกช่องทาง

ลำดับขั้นตอนด่วน

text
Open Google Cloud
-> Create or select a project
-> Enable Google Drive API
-> Configure Google Auth Platform
-> If Audience is External, add your Google account to Test users
-> Create a Web application OAuth client
-> Use https://your-domain.com/api/oauth/google/callback as the redirect URI
-> Fill Client ID and Client Secret into ImgHost
-> Click Get Token
-> Sign in with Google and authorize
-> Copy the Refresh Token from the callback page
-> Paste it back into ImgHost and save
-> Upload a test image

เอกสารอ้างอิง

  1. Google OAuth Web Server Applications: https://developers.google.com/identity/protocols/oauth2/web-server
  2. การกำหนดค่า OAuth Consent ของ Google Workspace: https://developers.google.com/workspace/guides/configure-oauth-consent
  3. Auth Scopes ของ Google Drive API: https://developers.google.com/workspace/drive/api/guides/api-specific-auth

Released as user documentation for ImgHost.