0

I am trying to integrate Salesforce with Google textsearch in order to acquire a JSON response with desired information. My request is getting denied and I can't figure out why. Any help is much appreciated.

httprequest req = new httprequest();
        http http = new http();
        req.setmethod('GET');

        string url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
            + '?query=' + name + '+'
            + city + '+'
            + state + '+'
            + zipcode
            + '&Key={MY-API-KEY}';
        req.setEndpoint(url);

        HttpResponse resp = http.send(req);
        system.debug(resp.getbody());
        string jsonResults = resp.getbody();

The response from this request is:

07:44:31.155 (155112095)|USER_DEBUG|[105]|DEBUG|{ "error_message" : "An internal error was found for this API project.", "html_attributions" : [], "results" : [], "status" : "REQUEST_DENIED" }

5
  • 1
    Google gets spammed with requests coming from same IP pool (Salesforce servers). Do you really have a valid key in your request and have you by any chance exhausted your daily quota? I did a mixed geocoding demo (client & server-side) at stackoverflow.com/questions/3122038/…, with client-side geocoding it'd use your IP instead of SF IP
    – eyescream
    Jul 30, 2014 at 12:05
  • @eyescream Thanks for the quick reply. The Places API is enabled in Google and the key is valid. Quota has not been met as I am making but a few requests daily. I have a geocoding API already in place that successfully gets lat and lng. I want to replace geocode api with place search api.
    – Berg
    Jul 30, 2014 at 12:38
  • 1
    developers.google.com/places/… ? Maybe the key should be lowercase... It's not exactly a SF question (because looks like callout succeeds, remote site settings are ok etc), there are few similar ones on StackOverflow or on code.google.com boards.
    – eyescream
    Jul 30, 2014 at 14:17
  • It worked! My other API has a capital 'K' as well and it works just fine. I am making them all lower case for uniformity. I copied the request from my other api and never thought to change 'Key' to 'key'. Thank you for the help!
    – Berg
    Jul 30, 2014 at 14:59

1 Answer 1

2

It turned out the problem was in this line of code:

  • '&Key={MY-API-KEY}';

Instead of using 'Key' I used 'key' and it worked.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .