私のウェブサイトでGoogle Signinを使用する方法を学びたいと思っています。私はこのページで見つけたガイドに従っています:https://developers.google.com/identity/sign-in/web/Googleログインでログアウトできない
私は新しい文書を作成し、上記のページで提案したコードをコピー/コピーしています。クライアントIDをタグに追加し、コードをテストしました。 すべてうまくいって、私はログインできました。ログインボタンが変更され、サインインの代わりにサインインされました。さらに、私は自分のコンソールを見て、ID、電子メール、名前のようなconsole.log()からデータを見ることができます...
I continueガイドを読むと、私は、このページ上のボタンをサインアウト追加する方法が見つかりました:私はそれをクリックすると、ここでhttps://developers.google.com/identity/sign-in/web/sign-in私はこのコードを実装し 、とは
<html lang="en">
<head>
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<a href="#" onclick="signOut();">Sign out</a>
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId()); // Don't send this directly to your server!
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());
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
};
</script>
<script>
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function() {
console.log('User signed out.');
});
}
</script>
</body>
</html>
(クライアントIDなし)私が持っている完全なコードであります「ユーザーがログアウトしました」というメッセージが表示されます。私のコンソールに。しかし、ページを更新すると、Googleのボタンはまだ私がサインインしていると言って、プロフィール情報が私のコンソールに戻ってきています。サインアウトボタンは明らかに機能しません。理由はわかりません。
誰でもその経験はありますか?
ありがとうございました!