ViralHeat API issues with getURL () command in RCurl package

I'm trying to find the “I'm not joking” mood (for example) using the viral Heat API using the R programming. I used getURL in the RCurl package, as shown below:

getURL (" https://www.viralheat.com/api/sentiment/review.json?text=i%20am%20happy&api_key= ", ssl.verifypeer = FALSE)

This works great in Google Chrome. But in IE, it redirects to " https://www.viralheat.com/browsers , because the ViralHeat API is not capable of IE Ver <9.

I changed the env R_BROWSER parameter in Google Chrome (which is my default browser). But getURL still uses IE, because when executing the above command, getURL is still redirected to the browsers page. I upgraded version of IE to 11. But it seems like viralheatAPI doesn't work on IE at all, as it is still redirecting to the browsers page.

Has anyone encountered this problem?

0
source share
1 answer

Requests made by RCurl do not use your browser. They should use their own RCURL library to create HTTP requests.

Most likely, the website checks the useragent line of the request to see if something is a valid browser. RCURL does not seem to indicate the default useragent line, as your browser does. If you want to impersonate Chrome, go to http://www.whatsmyuseragent.com/ to find out what your current useragent string is. Copy this value into a variable in R, then run

ua <- "<your full user agent here>" getURL("https://www.viralheat.com/api/sentiment/review.json?text=i%20am%20happy&api_key=", ssl.verifypeer=FALSE, .opts=list(useragent=ua)) 

and this should avoid the browser step in order to at least bring you to the API.

0
source

Source: https://habr.com/ru/post/1203885/


All Articles