是否可以使用Google帐户登录并将其信息保存到数据库

时间:2017-04-18 07:16:02

标签: php google-signin

我想知道有没有办法在用户登录谷歌帐户时将谷歌帐户信息添加到我的数据库中,当你使用G + api时它是可能的,但是当我不想要时它是可能的使用G + API,只想整合谷歌登录。 你们的帮助吗? 谢谢:))

<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<script>
function onSignIn(googleUser) {
    // Useful data for your client-side scripts:
    var profile = googleUser.getBasicProfile();
    console.log("ID: " + profile.getId()); // Don't send this directly to your server!
    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());

    // The ID token you need to pass to your backend:
    var id_token = googleUser.getAuthResponse().id_token;
    console.log("ID Token: " + id_token);
};

1 个答案:

答案 0 :(得分:0)

<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<script>
function onSignIn(googleUser) {
    // Useful data for your client-side scripts:
    var profile = googleUser.getBasicProfile();
    console.log("ID: " + profile.getId()); // Don't send this directly to your server!
    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());

    // The ID token you need to pass to your backend:
    var id_token = googleUser.getAuthResponse().id_token;
    console.log("ID Token: " + id_token);
    //You have your data in the variable `id_token`. Now send this to your server to be stored
};

您正在编写的代码是javascript。现在,您需要与服务器通信,以便将浏览器上的数据(驻留在javascript变量中)发送到服务器。

您有不同的选择 1.将数据设置为表单并提交 2.将数据设置为查询字符串并重定向 3.通过ajax将数据发送到服务器。

在服务器上,您需要使用php,java,c#等语言接收数据并写入数据库。

相关问题