rgoogle-mapsrjsonrjsonio

HTTP error 400 using Google Maps API


I am using the Google Places API to collect information about businesses. It has been working for more than 2000 queries but it has stopped now with the error

Error in open.connection(con, "rb") : HTTP error 400.

Code:

require(RJSONIO)
require(jsonlite)
require(utils)
place_url <- "https://maps.googleapis.com/maps/api/place/textsearch/json?query= "
key <- "Random_letters_generated_by_google"
setInternet2(TRUE)
query <- paste(business$name[1], city_name,country_name,sep = "+")
  str_url <- as.character(paste(place_url ,query,"&key=",key,sep=""))
  business_gis <- fromJSON(URLencode(str_url))

I have seen another question with the same error but related to html. How could I fix it for this case? Why has it stopped working? Any idea/hint is welcome.


Solution

  • When I had same problem, I took out spaces(replaced space with %20) and it worked for me.