问题描述
我看到了以前的,但我无法调整答案以获取我的代码正常工作。
I saw this previous post but I have not been able to adapt the answer to get my code to work.
我正在尝试过滤术语bruns,并且由于在Windows计算机上进行身份验证需要引用cacert.pem。最后,我编写了一个解析每个响应的函数(my.function),并且还需要包含它。
I am trying to filter on the term bruins and need to reference cacert.pem since for authentication on my Windows machine. Lastly, I have written a function to parse each response (my.function) and need to include this as well.
postForm("https://stream.twitter.com/1/statuses/sample.json",
userpwd="user:pass",
cainfo = "cacert.pem",
a = "bruins",
write=my.function)
我希望完全保留在R中
简单地,我如何包含所需的搜索词以过滤响应?
Simply, how can I include the search term(s) that I want such that the response is filtered?
谢谢。
推荐答案
好的,所以我看了看你通过查看,尽管可能很难弄清楚如何将某些示例转换为R(通过RCurl程序包)。
Alright, so I've looked at what you're doing, and some of what you're working on may be helped by examining the Twitter API methods, although it can be difficult to figure out how to translate some of the examples into R (via the RCurl Package).
您当前正在使用什么tr ying 非常非常接近您需要做的事情,您只需要更改两件事即可。
What you're currently trying is very close to what you need to do, you simply need to change two things.
首先,您要查询网址为状态的随机样本。此网址返回大约所有推文的1%的随机样本。
First of all, you're querying the url for the random sample of statuses. This url returns a random sample of roughly 1% of all tweets.
如果您只想收集有关特定关键字的推文,则希望使用过滤器API网址: https://stream.twitter.com/1/statuses/filter.json
If you're interested in collecting only tweets about specific keywords, you want to use the filter API url: "https://stream.twitter.com/1/statuses/filter.json"
更改后,您只需将参数从 a更改为到 postfields,您要传递的参数将类似于: track = bruins
After changing that, you simply need to change your parameter from "a" to "postfields", and the parameter you'd be passing would look like: "track=bruins"
最后,您应该使用getURL函数打开一个连续的流,因此可以收集所有带有关键字的推文,而不是使用postForm命令(我认为该命令适用于HTML表单)。
Finally, you should use the getURL function, to open a continuous stream, so all tweets with your keywords can be collected, rather than using the postForm command (which I believe is intended for HTML forms).
因此,您的最终函数调用应如下所示:
so your final function call should look like the following:
getURL("https://stream.twitter.com/1/statuses/filter.json",
userpwd="Username:Password",
cainfo = "cacert.pem",
write=my.function,
postfields="track=bruins")
这篇关于RCurl Twitter流API关键字过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!