我正在使用R中的twitteR
库,并想知道是否有可能获得与搜索或时间表相关联的时间戳。 E.G如果使用searchTwitter搜索#rstats,我想知道推文发布的时间......是否需要解析其他参数以获取该信息?
这是一些示例代码......
library(twitteR)
searchTwitter("#rstats",n=10)
给出以下结果
[[1]]
[1] "MinneAnalytics: @thomaswdinsmore RT @erikriverson: Some thoughts from an observer on the #Rstats track at #BigDataMN. http://t.co/i42PEQHz #R at #CSOM"
[[2]]
[1] "pentalibra: My package ggdendro to draw dendrograms with ggplot2 is back on CRAN. http://t.co/gMviOSnQ Wait a day or so for Windows binary/ #rstats"
[[3]]
[1] "Lachamadice: RT @freakonometrics: \"Regression tree using Gini's index\" http://t.co/tUplMqQj with #rstats"
[[4]]
[1] "Rbloggers: Tracking Number of Historical Clusters: \n(This article was first published on Systematic Investor » R,... http://t.co/jRnWUQ2Y #rstats"
[[5]]
[1] "Rbloggers: ggplot2 multiple boxplots with metadata: \n(This article was first published on mintgene » R, and kindl... http://t.co/re2gghTx #rstats"
[[6]]
[1] "Rbloggers: Learning R using a Chemical Reaction Engineering Book: Part 3: \n(This article was first published on N... http://t.co/agCJi9Rr #rstats"
[[7]]
[1] "Rbloggers: Learning R using a Chemical Reaction Engineering Book: Part 2: \n(This article was first published on N... http://t.co/2qqpgQrq #rstats"
[[8]]
[1] "Rbloggers: Waiting for an API request to complete: \n(This article was first published on Recology - R, and kindly... http://t.co/MZzxHVdw #rstats"
[[9]]
[1] "heidelqekhse3: RT @geospacedman: Just got an openlayers map working on an #rstats #shiny app at #nhshd but... meh."
[[10]]
[1] "jveik: Slides and replay of “Using R with Hadoop” webinar now available #rstats #hadoop | @scoopit http://t.co/Ar2F7We3"
答案 0 :(得分:4)
:
mytweet <- searchTwitter("#chocolate",n=10)
str(mytweet[[1]])
Reference class 'status' [package "twitteR"] with 10 fields
$ text : chr "The #chocolate part of the #croquette. #dumplings #truffles http://t.co/Imwt3tTP"
$ favorited : logi FALSE
$ replyToSN : chr(0)
$ created : POSIXct[1:1], format: "2013-01-27 16:26:03"
$ truncated : logi FALSE
$ replyToSID : chr(0)
$ id : chr "295568362526896128"
$ replyToUID : chr(0)
$ statusSource: chr "<a href="http://instagr.am">Instagram</a>"
$ screenName : chr "tahiatmahboob"
and 33 methods, of which 22 are possibly relevant:
getCreated, getFavorited, getId, getReplyToSID, getReplyToSN, getReplyToUID, getScreenName, getStatusSource, getText, getTruncated,
initialize, setCreated, setFavorited, setId, setReplyToSID, setReplyToSN, setReplyToUID, setScreenName, setStatusSource, setText,
setTruncated, toDataFrame
所以时间戳是:
mytweet[[1]]$created
[1] "2013-01-27 16:26:03 UTC"
在我阅读您的问题之前,从未使用twitteR
。无聊时似乎很有趣。
答案 1 :(得分:1)
解析结果的一个替代方案(如上面的答案)是使用参数从和直到。
例如,你可以这样做:
res <- searchTwitter("#rstats",n=1000,since='2013-01-24',
until='2013-01-28')
searchTwitter
是twitter的JSON API的包装器。请查看here以获取有关参数和JSON结果示例的更多详细信息。