我遵循Google Sign-in for Websites并为登录和退出创建了以下页面。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="google-signin-client_id" content="00000000000-MY CLIENT ID">
<title></title>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script type="text/javascript">
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
}
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.
}
</script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
<a href="#" onclick="signOut();">Sign out</a>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
我对这个样本有一些疑问。