将数据从Javascript传输到python

2024-04-25 19:52:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在添加谷歌登录到我的网站。为此,我在JavaScript的前端使用了以下代码:

<script>
function onSuccess(googleUser) {
    var profile = googleUser.getBasicProfile();
    gapi.client.load('plus', 'v1', function () {
        var request = gapi.client.plus.people.get({
            'userId': 'me'
        });
        //Display the user details
        request.execute(function (resp) {
            var profileHTML = '<div class="profile"><div 
class="head">Welcome '+resp.name.givenName+'! <a href="javascript:void(0);" 
onclick="signOut();">Sign out</a></div>';
            profileHTML += '<img src="'+resp.image.url+'"/><div 
class="proDetails"><p>'+resp.displayName+'</p>
<p>'+resp.emails[0].value+'</p><p>'+resp.gender+'</p><p>'+resp.id+'</p><p><a 
href="'+resp.url+'">View Google+ Profile</a></p></div></div>';
            $('.userContent').html(profileHTML);
            $('#gSignIn').slideUp('slow');
        });
    });

}
function onFailure(error) {
    alert(error);
}
function renderButton() {
    gapi.signin2.render('gSignIn', {
        'scope': 'profile email',
        'width': 240,
        'height': 50,
        'longtitle': true,
        'theme': 'dark',
        'onsuccess': onSuccess,
        'onfailure': onFailure
    });
}
function signOut() {
    var auth2 = gapi.auth2.getAuthInstance();
    auth2.signOut().then(function () {
        $('.userContent').html('');
        $('#gSignIn').slideDown('slow');
    });
}

</script>

现在,我希望用户的信息从他们的google帐户传输到我用python2.7编写的后端服务器代码中,这样用户就可以使用这些凭据登录到我的网站。我的web应用程序部署在GAE中。我不知道我该怎么做,也不知道我应该使用什么库。你知道吗


Tags: 代码div网站varscriptfunctionauth2profile