反应:Google的“一键式"回调函数未被调用 [英] React: Google "One Tap" callback function not being called

查看:201
本文介绍了反应:Google的“一键式"回调函数未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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?提示用户登录,单击继续,然后该函数将永远不会被调用! rr!以上摘录自此处的文档也在此处

Why does handleCredentialResponse not get called at all? The user is prompted to log in, they hit continue and then the function never gets called! Grrr! Above taken from docs here and also here

notification注销

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

推荐答案

您在本地测试吗?如前所述,此处,则需要同时添加 http://localhost http://localhost:port_number 到授权JavaScript来源"框.

are you testing locally? As mentioned here, you need to add both http://localhost and http://localhost:port_number to the Authorized JavaScript origins box.

这篇关于反应:Google的“一键式"回调函数未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆