Google: OAuth2 single service#
เอกสารนี้มีคำแนะนำในการสร้าง Google credential สำหรับบริการเดียว นอกจากนี้ยังมีในรูปแบบ video
หมายเหตุสำหรับผู้ใช้ n8n Cloud
สำหรับ nodes ต่อไปนี้ คุณสามารถยืนยันตัวตนได้โดยเลือก Sign in with Google ในส่วน OAuth:
Prerequisites#
- สร้างบัญชี Google Cloud
Set up OAuth#
มีห้าขั้นตอนในการเชื่อมต่อ credential ของ n8n กับบริการของ Google:
- Create a Google Cloud Console project
- Enable APIs
- Configure your OAuth consent screen
- Create your Google OAuth client credentials
- Finish your n8n credential
Create a Google Cloud Console project#
ขั้นแรก สร้างโปรเจกต์ Google Cloud Console หากคุณมีโปรเจกต์อยู่แล้ว ข้ามไปที่ส่วนถัดไป:
- ลงชื่อเข้าใช้ Google Cloud Console โดยใช้ Google credentials ของคุณ
- ในเมนูด้านบน เลือก project dropdown ในแถบนำทางด้านบน แล้วเลือก New project หรือไปที่หน้า New Project โดยตรง
- ป้อน Project name และเลือก Location สำหรับ project ของคุณ
- เลือก Create
-
ตรวจสอบแถบนำทางด้านบนและตรวจสอบให้แน่ใจว่า project dropdown ได้เลือก project ของคุณแล้ว หากยังไม่ได้เลือก ให้เลือก project ที่คุณเพิ่งสร้างขึ้น
Enable APIs#
เมื่อสร้างโปรเจกต์ของคุณแล้ว เปิดใช้งาน APIs ที่คุณต้องการเข้าถึง:
- เข้าถึง Google Cloud Console - Library ของคุณ ตรวจสอบให้แน่ใจว่าคุณอยู่ใน project ที่ถูกต้อง
ตรวจสอบ project dropdown ในแถบนำทางด้านบนของ Google Cloud - ไปที่ APIs & Services > Library
- ค้นหาและเลือก API ที่คุณต้องการเปิดใช้งาน ตัวอย่างเช่น สำหรับ Gmail node ให้ค้นหาและเปิดใช้งาน Gmail API
-
บาง integrations จำเป็นต้องใช้ API อื่นๆ หรือต้องการให้คุณขอสิทธิ์เข้าถึง:
- Google Perspective: Request API Access
- Google Ads: รับ Developer Token
ต้องการ 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 ด้วย
-
เลือก ENABLE
Configure your OAuth consent screen#
หากคุณไม่เคยใช้ OAuth ในโปรเจกต์ Google Cloud ของคุณมาก่อน คุณจะต้อง configure the OAuth consent screen:
- เข้าถึง Google Cloud Console - Library ของคุณ ตรวจสอบให้แน่ใจว่าคุณอยู่ในโปรเจกต์ที่ถูกต้อง
ตรวจสอบ dropdown ของโปรเจกต์ในแถบนำทางด้านบนของ Google Cloud - เปิดเมนูนำทางด้านซ้ายและไปที่ APIs & Services > OAuth consent screen
- สำหรับ User Type เลือก Internal สำหรับการเข้าถึงของผู้ใช้ภายใน Google Workspace ขององค์กรของคุณ หรือ External สำหรับผู้ใช้ใดๆ ที่มีบัญชี Google อ้างอิงเอกสาร User type documentation ของ Google สำหรับข้อมูลเพิ่มเติมเกี่ยวกับประเภทผู้ใช้
- เลือก Create
- ป้อนข้อมูลที่จำเป็น:
- App name
- User support email
- ฟิลด์ Email addresses ใน Developer contact information
- ในส่วน Authorized domains เพิ่ม
n8n.cloud
หากใช้บริการ Cloud ของ n8n หากคุณ self-hosting ให้เพิ่มโดเมนของ instance n8n ของคุณ - เลือก SAVE AND CONTINUE เพื่อไปยังหน้า Scopes
- คุณไม่จำเป็นต้องตั้งค่า scope ใดๆ เลือก SAVE AND CONTINUE อีกครั้งเพื่อไปยังหน้า Summary
- ในหน้า Summary ตรวจสอบข้อมูลเพื่อความถูกต้อง
Create your Google OAuth client credentials#
ถัดไป สร้าง OAuth client credentials ใน Google:
- ในส่วน APIs & Services เลือก Credentials
- เลือก + CREATE CREDENTIALS > OAuth client ID
- ใน dropdown Application type เลือก Web application
- Google จะสร้าง Name โดยอัตโนมัติ อัปเดต Name เป็นชื่อที่คุณจะจำได้ใน console ของคุณ
- จาก credential ของ n8n ของคุณ คัดลอก OAuth Redirect URL วางลงใน Authorized redirect URIs ใน Google Console
- เลือก CREATE
Finish your n8n credential#
เมื่อโปรเจกต์และ credentials ของ Google ได้รับการกำหนดค่าอย่างสมบูรณ์แล้ว ให้ดำเนินการ credential ของ n8n ให้เสร็จสิ้น:
- จาก modal OAuth client created ของ Google คัดลอก Client ID ป้อนค่านี้ใน credential ของ n8n ของคุณ
- จาก modal เดียวกันของ Google คัดลอก Client Secret ป้อนค่านี้ใน credential ของ n8n ของคุณ
- ใน n8n เลือก Sign in with Google เพื่อทำการยืนยันตัวตน Google ของคุณให้เสร็จสมบูรณ์
- 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