29

I ma using google maps in my app, and use the URL as following format without the API key- values,

<script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?sensor=SET_TO_TRUE_OR_FALSE">
    </script>

Now I need to use the API key to track the requests, according to the examples it needs to add another API key query string parameter,

<script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=SET_TO_TRUE_OR_FALSE">
</script>

But, I received 2 keys, One for servers (IP address restrictions) and one for browser apps (domain level restrictions) are as follows:

Server Key: XXXX Browser Key: YYYYY

Which key should I use in my app, should I use both of them? Could not find a good article on this.

user1406716
  • 9,565
  • 22
  • 96
  • 151
  • You should have two keys, a public key which you place in your JS, and a private key which you use to decrypt the content which you get back from google which is encrypted using your private key for which you are the only one who should have it. – Hydra IO Jul 18 '13 at 05:58
  • Should I use "Browser key" in my javascript? When should I use Serverkey then? Is it something to be done with the google account to view analytics? –  Jul 18 '13 at 06:05

3 Answers3

30

This is relevant again now that Google just recently deprecated Browser Keys for its Web Services APIs.

Here are the current definitions:

Server keys

Create and use a server key if your application runs on a server. Do not use this key outside of your server code. For example, do not embed it in a web page. To prevent quota theft, restrict your key so that requests are only allowed from your servers' source IP addresses.

Browser keys

Create and use a browser key if your application runs on a client, such as a web browser. To prevent your key from being used on unauthorized sites, only allow referrals from domains you administer.

(from https://developers.google.com/console/help/new/)

user
  • 3,938
  • 1
  • 23
  • 19
  • 3
    this should be beset answer, and user should have a real and more specific username ;) – Yannis Dran Apr 08 '16 at 10:27
  • use this link to get `browser key`: https://developers.google.com/maps/documentation/javascript/get-api-key#get-an-api-key and use this link to get `server key`: https://developers.google.com/maps/documentation/directions/get-api-key#premium-key. – Deke May 23 '16 at 22:23
5

Try the browser key, found this post, but it's written on 2012,

https://groups.google.com/forum/#!topic/android-gcm/Ir-dNtPRKcU

Found this on web: "2.Click Create new Server key. Either a server key or a browser key should work. The advantage to using a server key is that it allows you to whitelist IP addresses. The following screen appears:"

http://developer.android.com/google/gcm/gs.html

Hope this will help you!

Dhanuka777
  • 8,331
  • 7
  • 70
  • 126
  • 1
    I do use the Browser Key; but, I don't have a server key. I was just googling Browser Key vs Server Key. ha. So i'm going down the rabbit hole. I'll update. – nil Aug 29 '13 at 16:07
  • 3
    Browser key - browser key has to be configured with some domains. e.g. *.abc.com/*,localhost/*. If your google map access request is sent from these domains its fine. But if you use this key in another application (xyz.com), it will give a invalid key error... Server key has to be configured with IPs (IP white list). If the google map access requets are sent from these IPs, it will work.Otherwise it will throw up an error. I have tried all these scenarios. – Dhanuka777 Aug 30 '13 at 08:32
  • @Dhanuka777 what about the validity period of these two keys? – Surabhil Sergy Nov 27 '13 at 11:27
1

As of now (early 2018), I suspect the difference between server key and browser key is insignificant and only conceptual. Because the web console allows you to apply IP restriction or referrer restriction to any of your key. So, for the same key, you can apply a referrer restriction and then it works as a browser key, and you apply an IP restriction and then it works as a server key. Besides, I don't find specific documentation on server key vs browser key from this official help page.

RayLuo
  • 17,257
  • 6
  • 88
  • 73