google not recognizing my api key - javascript

I have created a google developers account. I have created a project in there. I have enabled the JavaScript maps API for the project, and I have created a browser key for it, and I have limited the usage of it to the domain of my web site that people will be viewing. When I go to do an autocomplete call on a form field in my page, I get the following error back in the response.
"This service requires an API key. For more information on authentication and Google Maps JavaScript API services please see: https://developers.google.com/maps/documentation/javascript/get-api-key"
So I read the page, and that's how and why I set everything up previously mentioned. But it still will not work, and I just can't figure out why.
What subtlety am I missing?
BTW, this is with Chrome if that means anything, haven't bothered with other browsers
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places&region=us" key="xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx"></script>

You're setting an HTML attribute. The key should instead be included in the src URL according to the link you posted.
Straight from their example:
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
type="text/javascript"></script>
Notice the location of "YOUR_API_KEY" in the URL. Your best bet when dealing with APIs like this is to look for examples and follow them as closely as you can, trying to understand them. Then modify them to suit your needs.

Related

Google Maps API DeletedApiProjectMapError

I have the exact same problem like Arul.
I am trying to use Google Maps API on my webpage but when I try to implement the map I've got DeletedApiProjectMapError.
First I went to the Error Messages site after I've tried many ways to include the script, like:
<script src="http://maps.googleapis.com/maps/api/js?v=3&key=API_KEY"></script>
//or
<script src="http://maps.googleapis.com/maps/api/js?key=API_KEY"></script>
//or
<script src="http://maps.googleapis.com/maps/api/js"></script>
and tried to add new API key on the Dev site but none of them works.
Is it possible that the error isn't on my side but on Google's?
I have found the solution to the problem.
You need to enable both the Google Maps Javascript API, and the Geocoding API.
https://console.developers.google.com/projectselector/apis/library
and
https://console.developers.google.com/google/maps-apis/apis/geocoding-backend.googleapis.com
Afterwards the error was RefererNotAllowedMapError instead of DeletedApiProjectMapError, but that was because I was running it on localhost - and it worked on the actual site after I added the domain in Credentials -> Domain Verification.
Just to add to the reply above with an image (and this solution worked for me while still staying on the local machine), because I was a bit confused about the enabling of APIs part.
Just navigate to:
https://console.developers.google.com/projectselector/apis/library
Select your project (for which you have an API)
On the right side expand the Maps API section and click on "Google Maps Javascript API" and the "Geocoding API"
On the page that appears you need to click on the "play" button to enable the API
Then you should be good to go without authorizing domains and continue working on the local machine.

Adding external api to EdX

I am currently creating a custom javascript problem which will sit in the Edx platform
http://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/exercises_tools/custom_javascript.html
I have created my Javascript in react.js and currently works outside of the EdX platform, but when I add it to EdX, it doesn't call the Google maps API. I am including it in EdX's raw HTML using the following link
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MY-API-KEY"></script>
I don't have any http referrers on the api key, so nothing is being blocked from using it.
No errors appear in the console. And despite an in-depth search, I can't find EdX documentation to tell me how to include the api.
Has anyone found a way to include, specifically Google maps, but any external APIs in to EdX?

Google api key not working [duplicate]

I am developing in JavaScript/HTML/CSS an app that uses Google Maps. I am getting the following alert dialog box:
"This page was unable to display a Google Maps element. The provided Google API key is invalid or this site is not authorized to use it. Error Code: InvalidKeyOrUnauthorizedURLMapError"
The app does actually display the map element; the alert is not a problem except it should not appear at all. The map displays properly.
I have gone in to the Google Developer's Console and, in the "Credentials" section, have "edited allowed referrers" to be mydomain.com/*
I have also gone in to the Google Developer's Console in the APIs section and enabled 11 Google Maps APIs.
After lots of referrer combinations, deleting and re-creating credentials i realized that i didn't enabled "Google Maps JavaScript API". What a shame. :)
For anyone who is having trouble to get google maps api work please check if the API enabled first.
After struggling a lot with this issue I've found 1 solution for me. It might help people who are searching for a proper and exact solution but not the comments, downvotes and links.
(Map was not displayed in my case.)
If suppose,the link of page where you are loading map is
http://example.com/abc/def/ghi/kpn.php
then give thesame(exactly the same) under Edit allowed references
If you try loading the same page using:
www.example.com/abc/def/ghi/kpn.php
or
http://www.example.com/abc/def/ghi/kpn.php
then your page is loaded but not your map, and this alert is generated.
CONCLUSION
Use the same path(Url address) at these 2 places.
While loading the page which has map.
Under Edit allowed references.
After following this I've got rid from this alert.
First you need to go to https://console.developers.google.com/ and select APIs.
In Google Maps APIs select Google Maps JavaScript API and make sure you enable API for Google Maps JavaScript.
Secondly, you need to create an API key:
Go to Credentials
Create new key and select Browser Key
No need to specify any referrers
So you should see Any referrer allowed after you save.
After a lot of trial and error this worked for me (by Eduardo. Thanks !)
The URL that needs to be authorized is the one in the Referrer header for the requests the browser sends to Google to load the API.
Under Browser Credentials > REFERERS
Add these
.example.org/
www.example.org/*
http://www.example.org
http://example.org
geocodezip provided the info i needed. I was indeed loading the googlemaps library twice: once in my index.html file and once in an iFrame. I changed my code so that the iFrame did not load the googlemaps library but, instead, used the parent. Thanks geocodezip!
Go to APIs menu and find "Google Maps JavaScript API" after you open it just press "Enable API"
I was able to get this to work by deleting all my referrers and allowing all. Apparently there is a bug in the developer console that is causing problems. Some people say that they can get referrers to work by deleting all then adding all back in at once instead of line by line:
https://productforums.google.com/forum/#!topic/maps/mSVyDazRMQo
Previous things I tried:
Regenerating Key
Setting all maps apis to enabled
Hard coding absolute paths of referrers
A side note, when I didn't include my api_key everything worked fined, though I'm sure they will eventually turn you off if you don't use your api_key.
What worked for me was to use Firebug in order to find the exact URL that made the request to the Google Maps API. As stated in Google Maps API documentation on troubleshooting authorization, "How to find the correct URL" part:
The URL that needs to be authorized is the one in the Referrer header
for the requests the browser sends to Google to load the API.
In my case, lets suppose I have a website example.com. In the developer console, under Google Maps API key, I've added many combinations of referrer such as example.com/*, *.example.com/*, example.com, but still the InvalidKeyOrUnauthorizedURLMapError persisted.
My solution, as I've mentioned, to use Firebug: open example.com and look for what was the referrer making request to https://maps.googleapis.com/maps/api/js?..., and it was http://example.com, and that is it. I've added http://example.com/* to the enabled URLs in the Developers Console under my respective API key and now everything works fine.
It is important to know where to look for on Firebug: it is the Net tab. Just click on the request to maps.googleapis ... and look for the Referer
I got it to work by exchanging the keys with my own special created keys AND reading this webpage a few times very carefully. My advice is to add or exchange your Google API Keys at https://console.developers.google.com/apis/credentials before embarking in very complicated scripting.
Insert your own API keys in the very first line of the Google Map javascript:
If you have been setup all configuration like api key etc, and you still got the error,
please enable all your mandatory APIs regarding to google maps.
Like:-
Google Maps Embed API
Google Maps Geocoding API
Google Maps Geolocation API
Google Maps JavaScript API

Facebook Developer Toolkit - difference between all.js and FeatureLoader.js.php

Ok can someone explain to me the difference between:
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
and
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
They seem to be two completely different libraries, but which one is newer? The way you call FB.init is different. In FeatureLoader.js.php, you pass in your App ID (numeric). In all.js, you pass in a Javascript map with the appId (alphanumeric).
One thing I've noticed is with the fb:login-button control, the all.js version has way more features. You can set custom text, and you can set "perms" to request certain permissions when the user is prompted to install the app. These are things I need to do.
However, if I use all.js, then the Facebook Developer Toolkit no longer works (IsConnected() returns false no matter what).. Is this because the Facebook Developer Toolkip doesn't support whatever API all.js is calling? This is a bummer because there is apparently no other way to request permissions on logon, and I'd have to have a separate popup to grant a permission.
Thanks!
Mike
The all.js URL is the new JS SDK and the FeatureLoader one is the older SDK. The new SDK is smaller, faster and better supported. It DOES support calling the REST API endpoints, just like the older one does, in addition to allowing you to call the Graph API using FB.api().
Ok did more research... seems all.js is the new OAuth 2.0/Graph API way of doing things, and Feature.js.php is the soon to be deprecated old-skool REST way of doing things..

iphone, uiwebview with JS (google maps API)

two question for you:
reading google documentation i've make an html with the JS for make a google maps api call.
I've put this file in my project, and in a TABView i read and render this file in a uiwebview.
Works great but every time i start my app and go to this view i got this message: "appleweb://someID want to use your current location".
Is my fault or is normal? why my authrization is not saved in position auth?
Second: if i must make some other request on my map and passing new data or refreshing existent data is better that i do this via javascript or there's some option in cocoa to refresh my view?
It is surely not your FAULT, and yes it is normal. user location authorization SHOULD NOT be saved because the next time user launches his app he wont be knowing that his current location is being used (just in case he wants to avoid that for whatever reason).
I dont know the answer to you second question but just a suggestion: why don't you use MapKit API provided by apple instead of going with html and js for google maps? It is pretty easy to use and theres enough documentation and sample codes available on ADC.

Categories

Resources