You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AMP项目是否支持Google One Tap登录功能?

Can Google One Tap be used on AMP pages?

Yes, you absolutely can integrate Google One Tap for login/registration into your AMP pages (including registration, landing, static, and blog pages). AMP supports this through the amp-auto-lightbox component and Google's Identity Services script, which is tailored to work within AMP's performance and security constraints. Here's a practical, step-by-step breakdown of how to implement it:

Implementation Steps

  1. Add the Required AMP Component
    First, include the amp-auto-lightbox script in your page's <head> section. This component lets you launch the One Tap flow in an AMP-compliant lightbox:

    <script async custom-element="amp-auto-lightbox" src="https://cdn.ampproject.org/v0/amp-auto-lightbox-0.1.js"></script>
    
  2. Set Up the One Tap Trigger
    Create a clickable element (like a button) to trigger the flow, then wrap the Google Identity Services script and configuration inside an amp-auto-lightbox container. Here's a working example:

    <amp-auto-lightbox id="google-one-tap-container" layout="nodisplay">
      <script async src="https://accounts.google.com/gsi/client" onload="initOneTap()"></script>
      <div id="g_id_onload"
           data-client_id="YOUR_GOOGLE_CLIENT_ID"
           data-login_uri="https://your-domain.com/handle-google-login"
           data-auto_prompt="false">
      </div>
      <div id="g_id_signin"></div>
    </amp-auto-lightbox>
    
    <button on="tap:google-one-tap-container.open">Sign in with Google</button>
    
    • Replace YOUR_GOOGLE_CLIENT_ID with the client ID from your Google Cloud project.
    • data-login_uri should point to your backend endpoint that will verify the Google ID token and create a user session.
  3. Validate the Token on Your Backend
    After the user completes the One Tap flow, Google will send an ID token to your specified login_uri. Use Google's official libraries (like the google-auth-library for Node.js) to validate this token, confirm its legitimacy, and then create a session for the user.

Key Considerations

  • AMP Compliance: Always use the latest versions of AMP components and the Google Identity Services script to avoid compatibility issues—AMP enforces strict rules for third-party scripts to maintain performance.
  • User Experience: The amp-auto-lightbox ensures the One Tap flow doesn't break AMP's fast-loading promise, providing a smooth, native-feeling experience for users.
  • Privacy & Terms: Make sure you're following Google's terms of service and relevant privacy laws (like GDPR) when handling user data from One Tap.

If you hit specific snags (like console errors or callback issues), share your code snippets and details, and we can troubleshoot further!

内容的提问来源于stack exchange,提问作者Steven Quinn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:59:02