Google Maps JavaScript API v3 for Work UnauthorizedURLforClientIdMapError

匿名 (未验证) 提交于 2019-12-03 02:34:02

问题:

I'm using Google Maps Web Services API for work, and they've given me a client ID. When I load up the main page, I don't get an error. However, when I click a sub-page, eg localhost:8080/pages/page.xhtml, I get an error called UnauthorizedURLforClientIdMapError, with the message that this URL is not authorized to use the provided Google Maps client ID.

For reference, Google discusses it in its documentation here: https://developers.google.com/maps/documentation/business/clientside/auth#registering_authorized_urls

With all that being said, I'm currently testing my server with TomCat using the URL http://localhost:8080. This domain has been authorized, as has my individual IP. In my view files, I'm adding this:

<script src="https://maps.googleapis.com/maps/api/js?    &amp;client=MY_CLIENT_ID         &amp;v=3.19         &amp;channel=MY_CHANNEL" type="text/javascript"></script> 

where 'MY_CLIENT_ID' and 'MY_CHANNEL' are obviously changed to suit my needs (my client id and channel are correct). I've searched through stack overflow and also read all of the relevant Google Documentation but I feel like I'm missing something very small (or large, I'd hope not though).

What's going on?

回答1:

Each URL that uses Google Maps for Work with the ClientID must be authorized to use that clientid.

You can find all the details here. But this is the summary:

  • The domain name or IP address does not have to be publicly accessible
  • All subdomains of a specified domain are also authorized.
  • All subpaths of an authorized path are also authorized.
  • Paths are case sensitive.
  • You may restrict valid URLs to those using certain ports.
  • HTTP and HTTPS protocols are considered different URLs.

If you are getting the UnauthorizedURLForClientIdMapError, look through the URL authorization rules and see if you simply need to add the URL to the list of authorized URLs.

Btw, here is the the list of Google Maps API Error Codes with explanations.



回答2:

You must allow the referred URLs related to that Client ID in the Google support management portal.

Access to the Google Support Management portal - http://www.google.com/enterprise/portal - , login with your enterprise google account, then in the left menu, go to "Maps, Manage Client ID" link, select you client id in the combo, and in the "Enter the URLs" textarea, write the referrer URL you want to authorize and click on "Add URL" button.

If you are using a ClientID instead an API KEY to authenticate to Google Maps services, the referrer URLs must be authorized here. If you are using an API KEY, yo must authorize the referrer urls from the google developers console.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!