Google static map API getting 403 forbidden when l

2020-02-26 15:17发布

What I have is a Google map that shows the location of a property but when I come to print the dynamic maps dont print so good so I decided to implement the Google Static Map image API.

http://lpoc.co.uk/properties-for-sale/property/oldgate-dairy-st-james-road-long-sutton-cambridgeshire-pe12/?prop-print=1

^^ is an example of a property in print view and should show a static map image but it fails to load and looking at my inspector I'm getting a 403 Forbiden response for the image.

But if I go to the URL directly the image loads...

What am I doing wrong?

Thanks

Scott

10条回答
对你真心纯属浪费
2楼-- · 2020-02-26 15:27

I had this same problem but my solution was different. I had the V2 maps api enabled, but not the static maps api (I thought this was V2). I enabled the static maps api and it worked.

查看更多
smile是对你的礼貌
3楼-- · 2020-02-26 15:32

Oops I feel like such an idiot. I was using the old V2 maps API URL and not the new V3 API URL. I was getting a 403 because I was using the V2 URL without providing an API key :(

查看更多
你好瞎i
4楼-- · 2020-02-26 15:34

Be hundred percent sure of these points: (for static maps)

  1. Enable your project at this url :

https://console.developers.google.com/apis/api/static_maps_backend/overview?project=

  1. You have your localhost, staging and production - all urls with wildcards enabled in the referrer section.

  2. Google has changed its policy and you now need an api key to display maps. refer this for more : Google Maps API without key?

Hope it helps.

查看更多
狗以群分
5楼-- · 2020-02-26 15:36

Yeah, Google Maps API version 3 were java-script version; "Google Static Maps" latest were 2.0. I suspect there might be some restriction on use.

查看更多
霸刀☆藐视天下
6楼-- · 2020-02-26 15:38

This has gotten quite a lot of views, so I'm adding my solution to the problem here:

When using the new API, make sure you generate a Key for browser apps (with referers) and also make sure the patterns match your URL.

E.g. when requesting from example.com your pattern should be

  example.com/*

When you're requesting from www.example.com:

  *.example.com/*

So make sure you check whether a subdomain is present and allow both patterns in the developer console.

  1. Visit the Developer Console.
  2. Under API Keys, click the pencil icon to edit.
  3. Under "Key restrictions", ensure that you have an entry for example.com/*, *.example.com/*, and any local testing domains you might want.
查看更多
\"骚年 ilove
7楼-- · 2020-02-26 15:42

now you should use 'signature' parameter, which you should add to request - otherwise static maps won't work. here is few useful links

1) how to generate signature

2) how to make signature on BE side (code snippet)

查看更多
登录 后发表回答