ViralHeat API issues with getURL() command in RCurl package

主宰稳场 提交于 2019-12-12 02:03:21

问题


I am trying to find the sentiment of "I am not joking" (For Example) using viral Heat API using R programming. I used getURL in RCurl package as shown below:

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

This is working fine in Google Chrome. But in IE it is getting redirected to "https://www.viralheat.com/browsers" as the ViralHeat API is incapable of IE Ver<9.

I changed the R_BROWSER env option to Google Chrome (which is my default browser). But getURL still uses IE as on execution of the above getURL command still redirects to browsers page. I upgraded the IE version to 11. But looks like viralheatAPI doesn't work on IE at all as it still getting redirected to browsers page.

Anybody faced this issue?


回答1:


Requests made by RCurl do not use your browser. They should use RCurl's own library for making HTTP requests.

Most likely the website checks the useragent string of the request to see it something is a valid browser. RCurl does not seem to specify a useragent string by default like your browser does. If you want to impersonate Chrome, go to http://www.whatsmyuseragent.com/ to see what your current useragent string is. Copy that value to 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 that should avoid the browser sniffing step to at least get you to the API.



来源:https://stackoverflow.com/questions/24418691/viralheat-api-issues-with-geturl-command-in-rcurl-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!