Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with Google Places API - INVALID REQUEST

Current I am experiencing an issue with my code where, in the last 3 days, I have been unable to successfully complete delete requests using the Google Places API, documented here.

Up until Sunday this code would execute and run without an issue as long as the requested place met the conditions in the API, and the only responses I received were of the OK or REQUEST_DENIED form.

Now, however, whenever I send a request the only responses I receive are of the form INVALID_REQUEST, which is very inconvenient to say the least. From my understanding, and the testing I performed on this code beforehand, I am complying with the format that they are requesting, so I can't understand why this isn't working.

Can anyone else look at this code and tell me if there are any problems compared to the linked API?

public boolean delete(String reference)
{
    try
    {
        System.out.println(reference);
        String url = "https://maps.googleapis.com/maps/api/place/delete/xml?sensor=false&key=API_KEY_HERE";

        String data = "<PlaceDeleteRequest>\n<reference>" + reference + "</reference>\n</PlaceDeleteRequest>";
        System.out.println(data);

        URL xmlUrl = new URL(url);
        HttpPost request = new HttpPost(xmlUrl.toURI());
        request.setEntity(new StringEntity(data));

        HttpClient client = new DefaultHttpClient();
        HttpResponse response = client.execute(request);
        HttpEntity entity = response.getEntity();

        BufferedReader input = new BufferedReader(new InputStreamReader(entity.getContent()));

        String line = "";

        while ((line = input.readLine()) != null) 
        {
            System.out.println(line);
            if (line.contains("<status>"))
            {
                String[] s1 = line.split(">");
                String[] s2 = s1[1].split("<");
                if (s2[0].equalsIgnoreCase("ok"))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        input.close();

    }
    catch(Exception e)
    {
        return false;
    }
    return false;
}
like image 700
forsterb01 Avatar asked Mar 20 '12 08:03

forsterb01


People also ask

How do I get more than 5 reviews on Google Places API?

In order to have access to more than 5 reviews with the Google API you have to purchase Premium data Access from Google. That premium plan will grant you access to all sorts of additional data points you have to shell out a pretty penny.

How do I integrate Google Places API on my website?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key. Click Close.


1 Answers

Personnally, I received INVALID_REQUEST response to my Google API requests because they were not enough spaced between eachother. I had to insert a sleep for 2 seconds between them for them to work.

like image 61
Michael Fayad Avatar answered Sep 20 '22 20:09

Michael Fayad