0

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.

Community
  • 1
  • 1
user3507584
  • 2,670
  • 5
  • 30
  • 54
  • I found the solution, it was a typo in the code leading to form the url. Morale: Errors on your connection may have nothing to do with the connection itself and more to usual typos/bugs. – user3507584 Dec 06 '16 at 19:21

1 Answers1

4

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

Stephen Rauch
  • 40,722
  • 30
  • 82
  • 105
Ravi Rai
  • 68
  • 8
  • 1
    For reference, my [`googleway`](https://cran.r-project.org/web/packages/googleway/index.html) package has a `google_places()` function that should handle all the encoding for you. – SymbolixAU Jul 21 '17 at 23:34