我是 Js 的初学者,我在 google devs 上多次检查 Google + 登录。我得到了我的 id 等。按钮现在做什么,它打开了一个谷歌窗口,但窗口中没有出现任何内容并关闭。我想要什么:如果接受条件等,人们就会建立联系。如果没有,请返回索引。如果成功,我想在我的谷歌电子邮件中获取用户的电子邮件。
请查看我的代码:
(JS in head)
<head>
<script type="text/javascript">
function signinCallback(authResult) {
if (authResult['access_token']) {
Successfully authorized;
// Hide the sign-in button now that the user is authorized, for example:
document.getElementById('signinButton').setAttribute('style', 'display: none');
} else if (authResult['error']) {
// There was an error.
// Possible error codes:
// "access_denied" - User denied access to your app
// "immediate_failed" - Could not automatially log in the user
console.log('There was an error: ' + authResult['error']);
}
}
</script>
<script type="text/javascript">
function disconnectUser(access_token) {
var revokeUrl = 'https://accounts.google.com/o/oauth2/revoke?token=' +
access_token;
// Perform an asynchronous GET request.
$.ajax({
type: 'GET',
url: revokeUrl,
async: false,
contentType: "application/json",
dataType: 'jsonp',
success: function(nullResponse) {
// Do something now that user is disconnected
// The response is always undefined.
},
error: function(e) {
// Handle the error
// console.log(e);
// You could point users to manually disconnect if unsuccessful
//https://plus.google.com/apps
}
});
}
// Could trigger the disconnect on a button click
$('#revokeButton').click(disconnectUser);
</script>
</head>
<body>
<span id="signinButton">
<span
class="g-signin"
data-callback="signinCallback"
data-clientid="id" (I got mine, it is not the problem)
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-scope="https://www.googleapis.com/auth/plus.login">
</span>
</span>
<!-- Place this asynchronous JavaScript just before your </body> tag -->
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async =
true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
</body>
oh i saw i've got a </div> before the </body> maybe it cause problem, i'll try to
put the </div> before the script, then </body>.
This is the url of google devs , Google + Sign-in button for the web :
https://developers.google.com/+/web/signin/
Thanks in advance for help!!