The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
From:
Dan <dl... @urbanschool.org>
Date: Sat, 16 Jun 2007 16:24:19 -0700
Local: Sat, Jun 16 2007 7:24 pm
Subject: api key
Hello,
If I have a website with multiple domains pointing to it, what would you suggest to do about API keys since the key only works for one of the domains?
Thanks, Daniel
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
jgeerdes <jgeer... @mchsi.com>
Date: Sat, 16 Jun 2007 17:45:52 -0700
Local: Sat, Jun 16 2007 8:45 pm
Subject: Re: api key
Use javascript to parse the domain from the document.location.href,
and then write the external script tag with the appropriate key.
Jeremy R. Geerdes Effective Website Design & Development
For more information or a project quote: http://jgeerdes.home.mchsi.com jgeer... @mchsi.com
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Dan <dl... @urbanschool.org>
Date: Sat, 16 Jun 2007 19:39:51 -0700
Local: Sat, Jun 16 2007 10:39 pm
Subject: Re: api key
What does parse the domain mean?
Thanks, Daniel
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
jgeerdes <jgeer... @mchsi.com>
Date: Sun, 17 Jun 2007 13:19:57 -0700
Local: Sun, Jun 17 2007 4:19 pm
Subject: Re: api key
To parse the domain name, you want to look at document.location.href
and use a regular expression to pull the domain name of the document's
absolute URL. Assuming that you've set up your API keys based on your
primary domains (e.g., mysite.com), I would do something like this:
var gMapKeys = []; gMapKeys['mysite.com'] = '...'; gMapKeys['yoursite.org'] = '...'; gMapKeys['thissite.net'] = '...'; gMapKeys['thatsite.us'] = '...'; var loc = document.location.href.match(/^https?:\/\/.*?\.(.*?)\/?/i) [1]; document.write('<script type=text/javascript src="http:// maps.google.com/maps?file=api&v=2&key="'+gMapKeys[loc]+'"></ script>\n');
You would want to make sure that this happens as the page is loading (i.e., not in the onload).
Jeremy R. Geerdes Effective Website Design & Development
For more information or a project quote: http://jgeerdes.home.mchsi.com jgeer... @mchsi.com
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"Barry Hunter" <barrybhun... @googlemail.com>
Date: Sun, 17 Jun 2007 22:05:06 +0100
Local: Sun, Jun 17 2007 5:05 pm
Subject: Re: api key
Using document.location.host, is easier than using .href :) It also means you test it in the same way that Google does in the API code ;)
On 6/17/07, jgeerdes <jgeer... @mchsi.com> wrote:
> To parse the domain name, you want to look at document.location.href > and use a regular expression to pull the domain name of the document's > absolute URL. Assuming that you've set up your API keys based on your > primary domains (e.g., mysite.com), I would do something like this:
> var gMapKeys = []; > gMapKeys['mysite.com'] = '...'; > gMapKeys['yoursite.org'] = '...'; > gMapKeys['thissite.net'] = '...'; > gMapKeys['thatsite.us'] = '...'; > var loc = document.location.href.match(/^https?:\/\/.*?\.(.*?)\/?/i) > [1]; > document.write('<script type=text/javascript src="http:// > maps.google.com/maps?file=api&v=2&key="'+gMapKeys[loc]+'"></ > script>\n');
> You would want to make sure that this happens as the page is loading > (i.e., not in the onload).
> Jeremy R. Geerdes > Effective Website Design & Development
> For more information or a project quote: > http://jgeerdes.home.mchsi.com > jgeer... @mchsi.com
--
Barry
- www.nearby.org.uk - www.geograph.org.uk -
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Michael Geary <M... @Geary.com>
Date: Sun, 17 Jun 2007 20:16:28 -0700
Local: Sun, Jun 17 2007 11:16 pm
Subject: Re: api key
If anyone would like a nice simple piece of code to handle the API
keys for multiple domains, try this:
<script type="text/javascript"> document.write( '<script src="http://maps.google.com/maps? file=api&v=2&key=' + { 'example.com': 'api-key-for-example.com', 'anotherexample.com': 'api-key-for-anotherexample.com' }[location.host] + '" type="text/javascript"><\/script>' ); </script>
-Mike
On Jun 17, 2:05 pm, "Barry Hunter" <barrybhun... @googlemail.com> wrote:
> Using document.location.host, is easier than using .href :) It also means
> you test it in the same way that Google does in the API code ;)
> On 6/17/07, jgeerdes <jgeer... @mchsi.com> wrote:
> > To parse the domain name, you want to look at document.location.href > > and use a regular expression to pull the domain name of the document's > > absolute URL. Assuming that you've set up your API keys based on your > > primary domains (e.g., mysite.com), I would do something like this:
> > var gMapKeys = []; > > gMapKeys['mysite.com'] = '...'; > > gMapKeys['yoursite.org'] = '...'; > > gMapKeys['thissite.net'] = '...'; > > gMapKeys['thatsite.us'] = '...'; > > var loc = document.location.href.match(/^https?:\/\/.*?\.(.*?)\/?/i) > > [1]; > > document.write('<script type=text/javascript src="http:// > > maps.google.com/maps?file=api&v=2&key="'+gMapKeys[loc]+'"></ > > script>\n');
> > You would want to make sure that this happens as the page is loading > > (i.e., not in the onload).
> > Jeremy R. Geerdes > > Effective Website Design & Development
> > For more information or a project quote: > >http://jgeerdes.home.mchsi.com > > jgeer... @mchsi.com
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
jp <jdp... @gmail.com>
Date: Tue, 03 Jul 2007 08:41:50 -0700
Local: Tues, Jul 3 2007 11:41 am
Subject: Re: api key
Hi,
Is there a way in this code to have default value for this code if it doesn't match any of the domains? eg:
'example.com': 'api-key-for-example.com', 'anotherexample.com': 'api-key-for-anotherexample.com' default: 'fail'
thanks
John
On Jun 18, 4:16 am, Michael Geary <M... @Geary.com> wrote:
> If anyone would like a nice simple piece of code to handle the API
> keys formultipledomains, try this:
> <script type="text/javascript"> document.write( > '<script src="http://maps.google.com/maps? > file=api&v=2&key=' + > { > 'example.com': 'api-key-for-example.com', > 'anotherexample.com': 'api-key-for-anotherexample.com' > }[location.host] + > '" type="text/javascript"><\/script>' ); > </script>
> -Mike
> On Jun 17, 2:05 pm, "Barry Hunter" <barrybhun... @googlemail.com> > wrote:
> > Using document.location.host, is easier than using .href :) It also means > > you test it in the same way that Google does in the API code ;)
> > On 6/17/07, jgeerdes <jgeer... @mchsi.com> wrote:
> > > To parse the domain name, you want to look at document.location.href > > > and use a regular expression to pull the domain name of the document's > > > absolute URL. Assuming that you've set up your API keys based on your > > > primarydomains(e.g., mysite.com), I would do something like this:
> > > var gMapKeys = []; > > > gMapKeys['mysite.com'] = '...'; > > > gMapKeys['yoursite.org'] = '...'; > > > gMapKeys['thissite.net'] = '...'; > > > gMapKeys['thatsite.us'] = '...'; > > > var loc = document.location.href.match(/^https?:\/\/.*?\.(.*?)\/?/i) > > > [1]; > > > document.write('<script type=text/javascript src="http:// > > > maps.google.com/maps?file=api&v=2&key="'+gMapKeys[loc]+'"></ > > > script>\n');
> > > You would want to make sure that this happens as the page is loading > > > (i.e., not in the onload).
> > > Jeremy R. Geerdes > > > Effective Website Design & Development
> > > For more information or a project quote: > > >http://jgeerdes.home.mchsi.com > > > jgeer... @mchsi.com
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
warden <andrew.leac... @googlemail.com>
Date: Tue, 03 Jul 2007 08:59:17 -0700
Local: Tues, Jul 3 2007 11:59 am
Subject: Re: api key
On Jul 3, 4:41 pm, jp <jdp
... @gmail.com> wrote:
> Hi,
> Is there a way in this code to have default value for this code if it > doesn't match any of the domains? eg:
> 'example.com': 'api-key-for-example.com', > 'anotherexample.com': 'api-key-for-anotherexample.com' > default: 'fail'
Have you tried the code? The default key ends up as "undefined".
However, you can define your own default thus:
<script type="text/javascript"> document.write( '<script src="http://maps.google.com/maps? file=api&v=2&key=' + ({ 'example.com': 'api-key-for-example.com', 'anotherexample.com': 'api-key-for-anotherexample.com' }[location.host] || 'mydefaultvalue') + '" type="text/javascript"><\/script>' ); </script>
Andrew
You must
Sign in before you can post messages.
You do not have the permission required to post.