--
因為
所以要更新
--
參考
- 總覽 | Sign In With Google | Google Developers
- 生成HTML代碼| 使用 Google 登錄 | 谷歌開發者
- 使用 JavaScript 函數處理憑據響應 | Sign In With Google | Google Developers
--
應用
使用起來更簡單了,這樣就可以使用 Google 登入了,當然前提是已經有申請 Google API 以及設定了相關的金鑰
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<html> <body> <script src="https://accounts.google.com/gsi/client" async defer></script> <script src="https://unpkg.com/jwt-decode/build/jwt-decode.js"></script> <div id="g_id_onload" data-client_id="YOUR_GOOGLE_CLIENT_ID" data-callback="handleCredentialResponse"> </div> <div class="g_id_signin" data-type="standard" data-size="large" data-theme="outline" data-text="sign_in_with" data-shape="rectangular" data-logo_alignment="left"> </div> <script> function handleCredentialResponse(response) { // decodeJwtResponse() is a custom function defined by you // to decode the credential response. const responsePayload = jwt_decode(response.credential); console.log("ID: " + responsePayload.sub); console.log('Full Name: ' + responsePayload.name); console.log('Given Name: ' + responsePayload.given_name); console.log('Family Name: ' + responsePayload.family_name); console.log("Image URL: " + responsePayload.picture); console.log("Email: " + responsePayload.email); } </script> </body> </html> |
--
1,959 total views, 1 views today