Skip to content

Google: OAuth2 single service#

เอกสารนี้มีคำแนะนำในการสร้าง Google credential สำหรับบริการเดียว นอกจากนี้ยังมีในรูปแบบ video

หมายเหตุสำหรับผู้ใช้ n8n Cloud

สำหรับ nodes ต่อไปนี้ คุณสามารถยืนยันตัวตนได้โดยเลือก Sign in with Google ในส่วน OAuth:

Prerequisites#

Set up OAuth#

มีห้าขั้นตอนในการเชื่อมต่อ credential ของ n8n กับบริการของ Google:

  1. Create a Google Cloud Console project
  2. Enable APIs
  3. Configure your OAuth consent screen
  4. Create your Google OAuth client credentials
  5. Finish your n8n credential

Create a Google Cloud Console project#

ขั้นแรก สร้างโปรเจกต์ Google Cloud Console หากคุณมีโปรเจกต์อยู่แล้ว ข้ามไปที่ส่วนถัดไป:

  1. ลงชื่อเข้าใช้ Google Cloud Console โดยใช้ Google credentials ของคุณ
  2. ในเมนูด้านบน เลือก project dropdown ในแถบนำทางด้านบน แล้วเลือก New project หรือไปที่หน้า New Project โดยตรง
  3. ป้อน Project name และเลือก Location สำหรับ project ของคุณ
  4. เลือก Create
  5. ตรวจสอบแถบนำทางด้านบนและตรวจสอบให้แน่ใจว่า project dropdown ได้เลือก project ของคุณแล้ว หากยังไม่ได้เลือก ให้เลือก project ที่คุณเพิ่งสร้างขึ้น

    The project dropdown in the Google Cloud top navigation
    ตรวจสอบ project dropdown ในแถบนำทางด้านบนของ Google Cloud

Enable APIs#

เมื่อสร้างโปรเจกต์ของคุณแล้ว เปิดใช้งาน APIs ที่คุณต้องการเข้าถึง:

  1. เข้าถึง Google Cloud Console - Library ของคุณ ตรวจสอบให้แน่ใจว่าคุณอยู่ใน project ที่ถูกต้อง
    The project dropdown in the Google Cloud top navigation
    ตรวจสอบ project dropdown ในแถบนำทางด้านบนของ Google Cloud
  2. ไปที่ APIs & Services > Library
  3. ค้นหาและเลือก API ที่คุณต้องการเปิดใช้งาน ตัวอย่างเช่น สำหรับ Gmail node ให้ค้นหาและเปิดใช้งาน Gmail API
  4. บาง integrations จำเป็นต้องใช้ API อื่นๆ หรือต้องการให้คุณขอสิทธิ์เข้าถึง:

    ต้องการ Google Drive API

    Integrations ต่อไปนี้ต้องการ Google Drive API รวมถึง API ของตัวเองด้วย:

    • Google Docs
    • Google Sheets
    • Google Slides

    Google Vertex AI API

    นอกเหนือจาก Vertex AI API แล้ว คุณจะต้องเปิดใช้งาน Cloud Resource Manager API ด้วย

  5. เลือก ENABLE

หากคุณไม่เคยใช้ OAuth ในโปรเจกต์ Google Cloud ของคุณมาก่อน คุณจะต้อง configure the OAuth consent screen:

  1. เข้าถึง Google Cloud Console - Library ของคุณ ตรวจสอบให้แน่ใจว่าคุณอยู่ในโปรเจกต์ที่ถูกต้อง
    The project dropdown in the Google Cloud top navigation
    ตรวจสอบ dropdown ของโปรเจกต์ในแถบนำทางด้านบนของ Google Cloud
  2. เปิดเมนูนำทางด้านซ้ายและไปที่ APIs & Services > OAuth consent screen
  3. สำหรับ User Type เลือก Internal สำหรับการเข้าถึงของผู้ใช้ภายใน Google Workspace ขององค์กรของคุณ หรือ External สำหรับผู้ใช้ใดๆ ที่มีบัญชี Google อ้างอิงเอกสาร User type documentation ของ Google สำหรับข้อมูลเพิ่มเติมเกี่ยวกับประเภทผู้ใช้
  4. เลือก Create
  5. ป้อนข้อมูลที่จำเป็น:
    • App name
    • User support email
    • ฟิลด์ Email addresses ใน Developer contact information
  6. ในส่วน Authorized domains เพิ่ม n8n.cloud หากใช้บริการ Cloud ของ n8n หากคุณ self-hosting ให้เพิ่มโดเมนของ instance n8n ของคุณ
  7. เลือก SAVE AND CONTINUE เพื่อไปยังหน้า Scopes
  8. คุณไม่จำเป็นต้องตั้งค่า scope ใดๆ เลือก SAVE AND CONTINUE อีกครั้งเพื่อไปยังหน้า Summary
  9. ในหน้า Summary ตรวจสอบข้อมูลเพื่อความถูกต้อง

Create your Google OAuth client credentials#

ถัดไป สร้าง OAuth client credentials ใน Google:

  1. ในส่วน APIs & Services เลือก Credentials
  2. เลือก + CREATE CREDENTIALS > OAuth client ID
  3. ใน dropdown Application type เลือก Web application
  4. Google จะสร้าง Name โดยอัตโนมัติ อัปเดต Name เป็นชื่อที่คุณจะจำได้ใน console ของคุณ
  5. จาก credential ของ n8n ของคุณ คัดลอก OAuth Redirect URL วางลงใน Authorized redirect URIs ใน Google Console
  6. เลือก CREATE

Finish your n8n credential#

เมื่อโปรเจกต์และ credentials ของ Google ได้รับการกำหนดค่าอย่างสมบูรณ์แล้ว ให้ดำเนินการ credential ของ n8n ให้เสร็จสิ้น:

  1. จาก modal OAuth client created ของ Google คัดลอก Client ID ป้อนค่านี้ใน credential ของ n8n ของคุณ
  2. จาก modal เดียวกันของ Google คัดลอก Client Secret ป้อนค่านี้ใน credential ของ n8n ของคุณ
  3. ใน n8n เลือก Sign in with Google เพื่อทำการยืนยันตัวตน Google ของคุณให้เสร็จสมบูรณ์
  4. Save credentials ใหม่ของคุณ

Video#

Troubleshooting#

Google hasn't verified this app#

หากใช้วิธีการยืนยันตัวตนแบบ OAuth คุณอาจเห็นคำเตือน Google hasn't verified this app เพื่อหลีกเลี่ยงปัญหานี้ คุณสามารถสร้าง OAuth credentials จากบัญชีเดียวกับที่คุณต้องการยืนยันตัวตน

หากคุณจำเป็นต้องใช้ credentials ที่สร้างโดยบัญชีอื่น (โดยนักพัฒนาหรือบุคคลที่สาม) ให้ทำตามคำแนะนำใน Google Cloud documentation | Authorization errors: Google hasn't verified this app

Google Cloud app becoming unauthorized#

สำหรับแอป Google Cloud ที่มี Publishing status ตั้งค่าเป็น Testing และ User type ตั้งค่าเป็น External การให้ความยินยอมและ token จะหมดอายุหลังจากเจ็ดวัน โปรดดูข้อมูลเพิ่มเติมที่ Google Cloud Platform Console Help | Setting up your OAuth consent screen หากต้องการแก้ไขปัญหานี้ ให้เชื่อมต่อแอปอีกครั้งใน n8n credentials modal