5

How do I use R to do a Google Custom search? I have the custom search engine id and the api key. I currently try to do this:

getURL("https://www.googleapis.com/customsearch/v1?key=API_KEY&cx=ENGINE_ID&q=searchterm")

and I get the following error:

Error in function (type, msg, asError = TRUE) : SSL certificate problem: unable to get local issuer certificate

Though I am able to get the results in json when I do a get request in the browser. Any clue on whats happening?

data-frame-gg
  • 131
  • 1
  • 8

2 Answers2

4

httr package worked!!

library(httr)
query="https://www.googleapis.com/customsearch/v1?key=API_KEY&cx=ENGINE_ID&q=SEARCH_TERM"
content(GET(query))
data-frame-gg
  • 131
  • 1
  • 8
3

set ssl.verifypeer=TRUE in getURL

getURL("https://www.googleapis.com/customsearch/v1?key=API_KEY&cx=ENGINE_ID&q=searchterm", ssl.verifypeer=TRUE)
Ricardo Saporta
  • 54,400
  • 17
  • 144
  • 178
  • It worked for me when I set `ssl.verifypeer" = FALSE`, which seems more logical anyway. The parameter is not mentioned in the help. – Mike Wise Nov 16 '16 at 15:57