กำลังเรียกดูข้อมูลโปรไฟล์
คำเตือน: ไลบรารี Google Sign-In ใช้ FedCM API โดยไม่ได้บังคับ และการใช้ API เหล่านี้จะกลายเป็นข้อกำหนด
ประเมินผลกระทบ เพื่อยืนยันว่าการลงชื่อเข้าใช้ของผู้ใช้ยังคงทำงานได้ตามที่คาดไว้
เราจะเลิกใช้งานการรองรับไลบรารี Google Sign-In โปรดดูข้อมูลเพิ่มเติมในคู่มือ
การเลิกใช้งานและหยุดให้บริการ
หลังจากลงชื่อเข้าใช้ผู้ใช้ด้วย Google โดยใช้ขอบเขตเริ่มต้นแล้ว คุณจะเข้าถึงรหัส Google, ชื่อ, URL โปรไฟล์ และอีเมลของผู้ใช้ได้
สำคัญ: อย่าใช้รหัส Google ที่ getId()
แสดงหรือข้อมูลโปรไฟล์ของผู้ใช้เพื่อสื่อสารกับผู้ใช้ที่ลงชื่อเข้าใช้อยู่ในปัจจุบันกับเซิร์ฟเวอร์แบ็กเอนด์
แต่ให้ส่งโทเค็นระบุตัวตน แทน ซึ่งสามารถตรวจสอบได้อย่างปลอดภัยในเซิร์ฟเวอร์
หากต้องการเรียกข้อมูลโปรไฟล์ของผู้ใช้ ให้ใช้เมธอด getBasicProfile()
เช่น
// auth2 is initialized with gapi.auth2.init() and a user is signed in. if ( auth2 . isSignedIn . get ()) { var profile = auth2 . currentUser . get (). getBasicProfile (); console. log ( 'ID: ' + profile . getId ()); console. log ( 'Full Name: ' + profile . getName ()); console. log ( 'Given Name: ' + profile . getGivenName ()); console. log ( 'Family Name: ' + profile . getFamilyName ()); console. log ( 'Image URL: ' + profile . getImageUrl ()); console. log ( 'Email: ' + profile . getEmail ()); }
หมายเหตุ: อีเมลของบัญชี Google อาจเปลี่ยนแปลงได้ ดังนั้นอย่าใช้อีเมลดังกล่าวเพื่อระบุตัวตนผู้ใช้ แต่ให้ใช้รหัสของบัญชีแทน ซึ่งคุณรับได้จากไคลเอ็นต์ด้วย getBasicProfile().getId()
และในแบ็กเอนด์จากการอ้างสิทธิ์ sub
ของโทเค็นรหัส
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-11-22 UTC
[null,null,["อัปเดตล่าสุด 2024-11-22 UTC"],[[["Google Sign-In library support is deprecated, and migration to FedCM APIs will be mandatory soon, requiring an impact assessment."],["After user sign-in, you can access basic profile information like Google ID, name, profile URL, and email address."],["Instead of Google IDs or profile data, utilize ID tokens for secure backend server authentication."],["Google account email addresses are subject to change, so use the account's ID for user identification on both client and backend."]]],[]]