一、打开谷歌控制台:https://console.developers.google.com/apis
二、点击创建凭据,如下图,填写项目地址等
三、创建好客户端id和秘钥后,填写对应的项目网址和登录页网址
四、修改oauth同意屏幕网站首页地址和隐私政策网址
五、代码部分如下:
<script src="https:///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)); }); }
如对本文有疑问, 点击进行留言回复!!
微信小程序wx.scanCode扫描条形码,偶尔出现条形码不正确导致查询失败
Android 入门第七讲01-数据存储(数据存储概述,文件存储(raw和asserts目录读写,data/data/包名目录读写,sdcard目录读写),SharedPreferences读写)
vue-axios系列:axios拦截器,配置请求头,配置请求参数
网友评论