Reputation: 37
I'm attempting to use the Google Places API to lookup a business by name and location, from within a google apps script. The script uses a Google Drive Spreadsheet as the source for the business name and location.
The part I am stuck on is the URLFetch call to Google Places. When I make the call I get a 'REQUEST DENIED' error. I assume this has something to do with my authentication. What authentication do I need to use, Oauth or the API Key?
I'm currently using the API Key, but its still failing. Is the API Key for use inside the script editor, or only for use in web apps hosted on outside domains?
EDIT: So, when I plug in my variables and hard code the URL I get good results, but I get the error when I generate the URL like this:
var options =
{
"query" : 'REI',
"key" : 'MYKEY',
"sensor" : false,
"location" : latlon,
"radius" : 8000,
};
var result = UrlFetchApp.fetch("https://maps.googleapis.com/maps/api/place/textsearch/json", options);
What am I missing?
Upvotes: 0
Views: 514
Reputation: 7957
The options that you pass to URLFetch are wrong. See the UrlFetch documentation for what you can pass as options.
Your call must be something like
var result = UrlFetchApp.fetch('https://maps.googleapis.com/maps/api/place/textsearch/output?query=REI&key=MYKEY&sensor=false&location=latlon&radius=8000')
Upvotes: 1