1

我正在使用twitteRR 中的库,想知道是否可以获得与搜索或时间线相关的时间戳。例如,如果使用 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"
4

2 回答 2

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 "&lt;a href=&quot;http://instagr.am&quot;&gt;Instagram&lt;/a&gt;"
 $ 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在我阅读您的问题之前从未使用过。无聊的时候可以做一些有趣的事情。

于 2013-01-27T16:27:46.193 回答
1

解析结果的一种替代方法(如上面的答案)是使用参数sinceuntil

例如,您可以这样做:

 res <- searchTwitter("#rstats",n=1000,since='2013-01-24',
                                       until='2013-01-28')

searchTwitter是 twitter 的 JSON API 的包装器。在此处查看参数的更多详细信息和 JSON 结果的示例。

于 2013-01-27T16:37:01.623 回答