web-dev-qa-db-ja.com

LocalhostからのGoogleサインインでのidpiframe_initialization_failed

このリンクに従ってGoogleサインインボタンを作成しようとしています。これまでのところ、アカウント選択ダイアログボックスが来ていますが、その後、コンソールに結果が表示されません。代わりに、ページの読み込み時にこのエラーが発生しています。

"idpiframe_initialization_failed", details: "Not a valid Origin for the client: http://localhos…itelist this Origin for your project's client ID."
details: "Not a valid Origin for the client: http://localhost has not been whitelisted for client ID 386404527657-q4ss06np5g27dllq5ds7aif42udkh7e5.apps.googleusercontent.com. Please go to https://console.developers.google.com/ and whitelist this Origin for your project's client ID."

コードは次のとおりです。

<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>
    <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>
  </body>
</html>

私は本当にこの問題を修正し、コンソールで結果を取得する必要があります。これを修正するために次に何をすべきかわかりません。これについて助けが必要です、ありがとう!

12
Shihan Khan

私はこの正確な問題を抱えていました この解決策 私のために働いた。

要するに、ブラウザのキャッシュをクリアします。

Chromeの場合:[設定]→[詳細]→[閲覧データを消去]→[キャッシュされた画像とファイル]

30
Nathan Wailes

私のために働いた解決策は、そのアプリケーションのGoogle開発者コンソールAPIでOriginをホワイトリストにすることでした。

3
Cliff Coulter

Googleサインインを提供するいくつかのサイトでこのエラーが発生しました。サイトを機能させるには(ページをリロードした後)、「show cookies and other site data」のaccounts.google.com cookieを「許可」する必要がありました。おそらく、ブラウザでサードパーティのCookieをブロックすることが根本的な原因であり、

0
gergelykocse