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

Google Maps JavaScript API上下文路径限制失效问题求助

Fixing UnauthorizedURLForClientIdMapError When Using Wildcards for Google Maps JavaScript API Referers

Looks like you're hitting a common gotcha with Google Maps Platform's client ID referer restrictions—wildcards don't work the way you might expect here. Let's break down why this error happens and how to fix it:

Why You're Seeing This Error

The UnauthorizedURLForClientIdMapError is triggered because the wildcard format you're using (https://example.com/*) doesn't align with the strict referer rules for Google Maps client IDs. Unlike API keys, client IDs have more restrictive patterns for authorized referrers.

Step-by-Step Fix

1. Use the Correct Referer Pattern for Client IDs

Instead of using https://example.com/*, use the following format to allow all paths under example.com:

  • Add https://example.com/ (make sure to include the trailing slash)
    This pattern automatically matches all subpaths under the root domain (like /abc/def, /xyz, etc.)

If you only need to allow paths under a specific prefix (e.g., /abc/), you can use:

  • https://example.com/abc/

2. Update Your Google Cloud Console Configuration

Head to your Google Cloud Console and adjust the authorized referrers for your client ID:

  1. Navigate to APIs & Services > Credentials in your Maps project
  2. Find your client ID and click the pencil icon to edit it
  3. In the Authorized referrers section:
    • Remove the invalid https://example.com/* entry
    • Add the correct pattern(s) mentioned above (e.g., https://example.com/)
  4. Save the changes and wait 5-10 minutes for the configuration to propagate (Google's settings can take a bit to update)

3. Verify and Troubleshoot

After updating:

  • Clear your browser's cache and cookies to ensure old authorization data isn't interfering
  • Double-check that your app's URL uses the same protocol (HTTPS/HTTP) as the authorized referrer pattern
  • If you're testing on a subdomain (e.g., dev.example.com), make sure to add that as a separate authorized referrer entry too

Client IDs are a legacy authentication method for Google Maps Platform. If possible, switch to using an API key—they have more flexible wildcard rules:

  • You can directly use https://example.com/* to match all paths under the domain
  • https://*.example.com/* works for all subdomains and their paths

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 08:07:32