【问题标题】:Uncaught Failed to get parent origin from URL hash无法从 URL 哈希中获取父源
【发布时间】:2026-02-01 03:50:01
【问题描述】:

我正在尝试为我的网络应用设置 google 登录。目前,它处于开发状态并在http://localhost:8080/auth 上运行。我正在使用 Google 提供的默认登录按钮进行用户登录。每当打开新的 iFrame 进行用户身份验证时,它都会无限挂起。当我检查控制台时,那里显示了以下错误消息:

Uncaught 无法从 URL 哈希中获取父源!

不知道是什么问题。我在各种平台上搜索,但在任何地方都没有找到解决方案,甚至没有讨论这个问题的线程。 SO(12)上也有类似的问题,但没有答案。这就是我的简单 HTML 代码的样子:

<html>
  <head>
    <script src="https://apis.google.com/js/platform.js" async defer></script>
    <meta name="google-signin-client_id" content="client-id-prefix.apps.googleusercontent.com">
  </head>
  <body>
    <div class="g-signin2" data-onsuccess="onSignIn"></div>
  </body>
</html>

有人可以帮忙吗?它会帮助我,可能还有其他两个今天问过这个问题的人。

【问题讨论】:

    标签: javascript html web-applications google-oauth


    【解决方案1】:

    我发现了错误。我没有在 Credential -> My OAuth Client ID -> Authorized JavaScript origins 下注册我的域。通过添加,它开始工作。

    这是您的凭据:https://console.developers.google.com/apis/credentials

    【讨论】:

    • 哈哈哈你绿色检查了你自己的答案,太棒了!