zoukankan      html  css  js  c++  java
  • Web网站实现Google登录

    一、打开谷歌控制台:https://console.developers.google.com/apis

    二、点击创建凭据,如下图,填写项目地址等

    三、创建好客户端ID和秘钥后,填写对应的项目网址和登录页网址

    四、修改OAuth同意屏幕网站首页地址和隐私政策网址

    五、代码部分如下:

    <script src="https://apis.google.com/js/api:client.js"></script>function google_login() {
            var googleUser = {};
                gapi.load('auth2', function(){
                    // Retrieve the singleton for the GoogleAuth library and set up the client.
                    auth2 = gapi.auth2.init({
                        client_id: '申请得到的客户端ID', //客户端ID
                        cookiepolicy: 'single_host_origin',
                        scope: 'profile' //可以请求除了默认的'profile' and 'email'之外的数据
                    });
                    attachSignin(document.getElementById('google_button')); //点击google登录的按钮
                });
    
        }
    
        function attachSignin(element) {
            auth2.attachClickHandler(element, {},
                function(googleUser) {
                    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());
                }, function(error) {
                    console.log(JSON.stringify(error, undefined, 2));
                });
        }
  • 相关阅读:
    RramSim2
    DiskSim
    FTL2
    Durable NAND flash memory management
    node系列:全局与本地
    CSS系列:less备忘
    Sql Server 2008:调试
    JavaScript系列:再巩固-原型链
    移动端 :meta标签1万个作用
    Asp.Net:Repeater 详情 备用
  • 原文地址:https://www.cnblogs.com/phperlinxinlan/p/11121555.html
Copyright © 2011-2022 走看看