【问题标题】:React: Google "One Tap" callback function not being called反应:谷歌“一键”回调函数没有被调用
【发布时间】:2020-07-21 14:36:12
【问题描述】:
<script src="https://accounts.google.com/gsi/client"></script>
...
declare var google: any;
...

  useEffect(() => {
    const handleCredentialResponse = (response: any) => {
      console.log(response);
    };
    const client_id = process.env.REACT_APP_GOOGLE_CLIENT_ID;
    const callback = handleCredentialResponse;
    const auto_select = true;
    google.accounts.id.initialize({ client_id, callback, auto_select });
    google.accounts.id.prompt((notification: any) => {
      console.log(notification);
    });
  }, []);

为什么handleCredentialResponse 根本不被调用?提示用户登录,他们点击继续,然后该函数永远不会被调用!呸!以上取自docs herealso here

notification 注销

nl {g: "display", h: true}
nl {g: "skipped", l: "issuing_failed"}

【问题讨论】:

  • 嗨@Bill,你从哪里引用了这段代码?根据文档,我只能看到此代码
  • 这里的谷歌变量是什么?

标签: reactjs google-oauth


【解决方案1】:

你在本地测试吗?正如提到的here,您需要将http://localhosthttp://localhost:port_number 添加到Authorized JavaScript origins 框中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-25
    • 1970-01-01
    • 2017-07-26
    • 2013-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多