Skip to content

Google: OAuth2 generic#

เอกสารนี้มีคำแนะนำในการสร้าง Google OAuth2 credential แบบทั่วไปสำหรับใช้กับ custom operations

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

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

Prerequisites#

Set up OAuth#

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

Create a Google Cloud Console project#

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

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

    The project dropdown in the Google Cloud top navigation
    ตรวจสอบ 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 เพื่อไปยังหน้า Data Access และเปิด Add or remove 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. คุณต้องระบุ scope สำหรับ credential นี้ อ้างอิง Scopes สำหรับข้อมูลเพิ่มเติม ป้อนหลาย scope โดยคั่นด้วยช่องว่าง ตัวอย่างเช่น:
    1
    https://www.googleapis.com/auth/gmail.labels https://www.googleapis.com/auth/gmail.addons.current.action.compose
    
  4. ใน n8n เลือก Sign in with Google เพื่อทำการยืนยันตัวตน Google ของคุณให้เสร็จสมบูรณ์
  5. Save credentials ใหม่ของคุณ

Video#

วิดีโอต่อไปนี้สาธิตขั้นตอนที่อธิบายไว้ข้างต้น:

Scopes#

บริการของ Google มี scope การเข้าถึงที่เป็นไปได้อย่างน้อยหนึ่งรายการ scope จะจำกัดสิ่งที่ผู้ใช้สามารถทำได้ อ้างอิง OAuth 2.0 Scopes for Google APIs สำหรับรายการ scope ของบริการทั้งหมด

n8n ไม่รองรับ scope ทั้งหมด เมื่อสร้าง Google OAuth2 API credential แบบทั่วไป คุณสามารถป้อน scope จากรายการ Supported scopes ด้านล่าง หากคุณป้อน scope ที่ n8n ยังไม่รองรับ มันจะไม่ทำงาน

Supported scopes
Service Available scopes
Gmail https://www.googleapis.com/auth/gmail.labels
https://www.googleapis.com/auth/gmail.addons.current.action.compose
https://www.googleapis.com/auth/gmail.addons.current.message.action
https://mail.google.com/
https://www.googleapis.com/auth/gmail.modify
https://www.googleapis.com/auth/gmail.compose
Google Ads https://www.googleapis.com/auth/adwords
Google Analytics https://www.googleapis.com/auth/analytics
https://www.googleapis.com/auth/analytics.readonly
Google BigQuery https://www.googleapis.com/auth/bigquery
Google Books https://www.googleapis.com/auth/books
Google Calendar https://www.googleapis.com/auth/calendar
https://www.googleapis.com/auth/calendar.events
Google Cloud Natural Language https://www.googleapis.com/auth/cloud-language
https://www.googleapis.com/auth/cloud-platform
Google Cloud Storage https://www.googleapis.com/auth/cloud-platform
https://www.googleapis.com/auth/cloud-platform.read-only
https://www.googleapis.com/auth/devstorage.full_control
https://www.googleapis.com/auth/devstorage.read_only
https://www.googleapis.com/auth/devstorage.read_write
Google Contacts https://www.googleapis.com/auth/contacts
Google Docs https://www.googleapis.com/auth/documents
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.file
Google Drive https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.appdata
https://www.googleapis.com/auth/drive.photos.readonly
Google Firebase Cloud Firestore https://www.googleapis.com/auth/datastore
https://www.googleapis.com/auth/firebase
Google Firebase Realtime Database https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/firebase.database
https://www.googleapis.com/auth/firebase
Google Perspective https://www.googleapis.com/auth/userinfo.email
Google Sheets https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/spreadsheets
Google Slide https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/presentations
Google Tasks https://www.googleapis.com/auth/tasks
Google Translate https://www.googleapis.com/auth/cloud-translation
GSuite Admin https://www.googleapis.com/auth/admin.directory.group
https://www.googleapis.com/auth/admin.directory.user
https://www.googleapis.com/auth/admin.directory.domain.readonly
https://www.googleapis.com/auth/admin.directory.userschema.readonly

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