google-apps-script - 如何将 Google 登录集成到您的 google 脚本网络应用程序中
问题描述
我想将谷歌登录集成到你的谷歌脚本中,有人帮我怎么办?一步步。我有文件 html 主页!tks哥们。
解决方案
要将 Google 登录集成到您的网络,您可以按照以下文章中提到的过程进行操作:
https://developers.google.com/identity/sign-in/web/sign-in
此外,如果您需要有关如何在代码中集成 HTML 的更多信息,可以阅读以下链接:
https://developers.google.com/apps-script/guides/html/
最后,这是一个关于如何做到这一点的实现示例(仅缺少 clientID):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="google-signin-client_id" content="#clientId">
<title>Oauth2 web</title>
<!-- Google library -->
<script src="https://apis.google.com/js/platform.js" async defer></script>
<!-- Jquery library to print the information easier -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<!-- Bootstrap library for the button style-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div id="profileinfo">
</div>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
<script>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
$("#profileinfo").append("<h2>Sup " + profile.getName() + ", welcome home my friend</h2>");
$("#profileinfo").append("<img style='width:250px;height:250px' src='" + profile.getImageUrl() + "'><br><br>");
$("#profileinfo").append("<p>Your email is: " + profile.getEmail() + "</p>");
}
</script>
<button type="button" class="btn btn-danger" onclick="signOut();">Sign out</button>
<script>
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
$("#profileinfo").empty();
$("#profileinfo").append("<h2>Goodbye old friend</h2>");
});
}
</script>
</body>
</html>
推荐阅读
- javascript - Javascript 和 JQuery 简洁的表单提交
- node.js - 发布请求:通过 Mongoose 中的数组发送值
- google-cloud-storage - 一段时间后从谷歌云存储桶中永久删除版本化对象
- pandas - 如何测试字符串是否在熊猫数据框的单元格中,单元格包含字符串列表?
- r - 在 r 中使用 lubridate 将字符串转换为日期类型
- https - 如何在自由配置文件中启用 MobileFirst Analytic https 端口
- powershell - Export-Csv - 拒绝访问路径“C:\export.csv”
- python-3.x - 使用beautifulsoup和pandas抓取时如何将行附加到xlsx文件?
- ruby-on-rails - 创建时Rails运行关联的验证?
- javascript - js触发基于子元素id的点击