javascript - Next js AMP amp-onetap-google 不工作
问题描述
我正在尝试在我的下一个 js amp 页面上添加谷歌一键。该实现基于基于此文档https://developers.google.com/identity/gsi/web/amp/intermediate-iframe的中间 iframe 方法
这是代码
托管中间 iframe 页面
/pages/amp-gtap-iframe.js
function AmpGtapIframe(props) {
// logic to initialize google gsi , not sure if this is needed but even with this the AMP page one tap does not work
const handleGoogleLogin = async (response) => {
//logic to handle login
};
const initializeGSI = () => {
google.accounts.id.initialize({
client_id: GOOGLE_CLIENT_ID,
cancel_on_tap_outside: false,
callback: handleGoogleLogin,
});
};
useEffect(() => {
const el = document.createElement('script');
el.setAttribute('src', 'https://accounts.google.com/gsi/client');
el.onload = () => initializeGSI();
document.querySelector('body').appendChild(el);
}, []);
/////////
return (
<div id="g_id_onload"
data-client_id="YOUR_GOOGLE_CLIENT_ID"
data-allowed_parent_origin="https://example.com">
</div>
);
}
export async function getStaticProps(context) {
return {
props: {},
};
}
export default AmpGtapIframe;
下一个js amp页面
/pages/amp-page.js
export const config = {
amp: true,
};
function AmpPage(props) {
return (
<div>
<amp-onetap-google
layout="nodisplay"
data-src="https://example.com/amp-gtap-iframe"
></amp-onetap-google>
</div>
);
}
export async function getStaticProps(context) {
return {
props: {},
};
}
export default AmpPage;
当我转到 example.com/amp-page 时,我得到一个 iframe,但未呈现 google 登录的电子邮件 ID
不知道我做错了什么,或者我对实现的理解不正确,非常感谢任何帮助,在此先感谢。
解决方案
推荐阅读
- r - .r 文件扩展名的大小限制是多少?
- sql - 根据多列分组查找最近更新的行
- python - 在函数调用上使用 tqdm 进度条
- r - 如何在r中将数据类型因子转换为double?
- javascript - 如何在 Highcharts 中按状态和图表对 SharePoint 项目的数量进行分组?
- php - Ajax 没有将我重定向到下一页
- python-3.x - 神经网络批量标准化中 Gamma 和 Beta 的初始化
- sql - ilike "%s%" 查询中的 SQL 排序顺序
- python - Python:嵌套列表迭代
- python - str.replace() 和 replace() 熊猫数据框的问题