Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Sau khi khởi chạy ứng dụng Đăng nhập bằng Google, bạn có thể đính kèm các trình xử lý kiểm tra nhiều thuộc tính và phương thức của ứng dụng để xác định trạng thái phiên của người dùng. Bạn có thể sử dụng thông tin do đối tượng ứng dụng trả về để giúp đồng bộ hoá trải nghiệm người dùng của trang web trên nhiều thẻ và thiết bị cho người dùng.
Mã sau đây minh hoạ cách sử dụng phương thức ứng dụng 2.0 attachClickHandler để tạo lệnh gọi lại tự động hoàn tất quy trình đăng nhập của người dùng hoặc nhắc người dùng uỷ quyền lại dựa trên trạng thái phiên của người dùng.
/***TheSign-Inclientobject.*/varauth2;/***InitializestheSign-Inclient.*/varinitClient=function(){gapi.load('auth2',function(){/***RetrievethesingletonfortheGoogleAuthlibraryandsetupthe*client.*/auth2=gapi.auth2.init({client_id:'CLIENT_ID.apps.googleusercontent.com'});//Attachtheclickhandlertothesign-inbuttonauth2.attachClickHandler('signin-button',{},onSuccess,onFailure);});};/***Handlesuccessfulsign-ins.*/varonSuccess=function(user){console.log('Signed in as '+user.getBasicProfile().getName());};/***Handlesign-infailures.*/varonFailure=function(error){console.log(error);};
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-06-06 UTC."],[[["The Google Sign-In JavaScript library is deprecated and will eventually be sunset; developers should consult the Deprecation and Sunset guide for migration details and timelines."],["Google Sign-In will require the use of FedCM APIs in the future, so developers should conduct an impact assessment to ensure their sign-in functionality remains unaffected."],["This page provides code demonstrating how to initialize the Google Sign-In client and attach click handlers to manage user sign-in and session state."],["Developers can utilize the `auth2` object to handle successful and failed sign-in attempts, accessing user information upon successful authentication."]]],[]]