• web网站接入谷歌登录


    一、打开谷歌控制台: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));
                });
        }
  • 相关阅读:
    使用pycharm调用模块后字体变灰
    spring注解驱动开发
    spring注解驱动开发
    spring注解驱动开发
    Centos6.5 防火墙开放端口
    fastJson一些补充
    springboot使用hibernate validator校验
    swagger的使用
    rabbitmq的vhost与用户管理
    解决mysql中只能通过localhost访问不能通过ip访问的问题
  • 原文地址:https://www.cnblogs.com/weixiaofantasy/p/14696831.html
Copyright © 2020-2023  润新知