hrbrmstr / curlconverter

:curly_loop: :arrow_right: :heavy_minus_sign: Translate cURL command lines into parameters for use with httr or actual httr calls (R)
http://rud.is/b/2016/02/10/craft-httr-calls-cleverly-with-curlconverter/
Other
91 stars 12 forks source link

Example on website does not work #6

Closed JackStat closed 8 years ago

JackStat commented 8 years ago

I get an error when I run the example on the website

REP <- "curl 'http://graphics.latimes.com/election-2016-31146-feed.json' -H 'Pragma: no-cache' -H 'DNT: 1' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'X-Requested-With: XMLHttpRequest' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.39 Safari/537.36' -H 'Accept: */*' -H 'Cache-Control: no-cache'  -H 'Cookie: s_fid=79D97B8B22CA721F-2DD12ACE392FF3B2; s_cc=true' -H 'Connection: keep-alive' -H 'If-Modified-Since: Wed, 10 Feb 2016 16:40:15 GMT' -H 'Referer: http://graphics.latimes.com/election-2016-new-hampshire-results/' --compressed"

resp <- curlconverter::straighten(REP)
jsonlite::toJSON(resp, pretty=TRUE)

curlconverter::make_req(REP)

#> Error in req$headers : $ operator is invalid for atomic vectors
ghost commented 8 years ago

Take a look at the examples in the README here. The pkg has gone through alot of changes since the blog post. Try:

curlconverter::make_req(resp, quiet=FALSE)

It was a paradigm shift posited by some folks to make it possible to

straighten(REP) %>% make_req() 

or

make_req(straighten(REP))