Tweets for a specific period of time (TwitteR)

Is there a way to get tweets for a specific amount of time (say between December and January) using twitteR and not just past N tweets (as in tweets <- UserTimeline (user, n = 1000)?

Or is this not possible using the TwitteR library? (this means you should be using something like Excel to subset a large number of tweets by date).

+3


source to share


2 answers


In the package you are using, the function searchTwitter

takes arguments since

and until

, defined in the documentation as follows:

since If not NULL, restricts tweets to those from the specified date. The date must be formatted as YYYY-MM-DD

before If not NULL, limits tweets to those before the specified date. The date must be formatted as YYYY-MM-DD

Is this what you need? Or if you want to stick with the function userTimeline

, you can multiply the date range you want by working on the field of the created

object status

you get (so no need to use Excel).

EDIT . You can subset in the field here created

if you use userTimeline

:



library(twitteR)
# get last 100 tweets from the NSF
tweets <- userTimeline('NSF', 100)
# inspect structure of first item in the status object (ie. list of results)
str(tweets[1])
List of 1
 $ :Reference class 'status' [package "twitteR"] with 10 fields
  ..$ text        : chr "From the field: Avoiding a Cartography Catastrophe:  Study recommends new tools to improve global mapping of inf... http://t.co"| __truncated__
  ..$ favorited   : logi FALSE
  ..$ replyToSN   : chr(0) 
  ..$ created     : POSIXct[1:1], format: "2013-02-05 01:43:45"
  ..$ truncated   : logi FALSE
  ..$ replyToSID  : chr(0) 
  ..$ id          : chr "298607815617036288"
  ..$ replyToUID  : chr(0) 
  ..$ statusSource: chr "<a href=\"http://twitterfeed.com\" rel=\"nofollow\">twitterfeed</a>"
  ..$ screenName  : chr "NSF"
  ..and 34 methods, of which 23 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, usingMethods


# convert status object to data frame for easier manipulation
tweetsdf <- twListToDF(tweets)


 # subset by `created` field, eg get all tweets between 2 Feb and 5 Feb  
    subset(tweetsdf, created >= as.POSIXct('2013-02-02 00:00:00') & created <= as.POSIXct('2013-02-05 00:00:00'))

      

And here is the dataframe that arises from this subset operation:

text
1   From the field: Avoiding a Cartography Catastrophe:  Study recommends new tools to improve global mapping of inf... http://t.co/F6IJ05Sb
2                  Video: Research Vessel Sikuliaq launched... and now being prepared for her first Arctic run in 2014, http://t.co/D7GlRnlm
3                                                                                        Who watching the power grid? http://t.co/oYsgBl63
4 Ice Melt &amp; the Ice Age... research story on #AAAS #Science Update Daily, featured show @Science360 Radio, http://t.co/XRXSdYL1 #Arctic
5                                                                                             Taking LIGO to the people http://t.co/R2KHNQTB
6                            Pubs: NSF Current - January-February 2013: Available Formats: JSP: http://t.co/2NhEEj6Q... http://t.co/ZSVABpXm
7   Upcoming Due Dates: Interdisciplinary Research in Hazards and Disasters (Hazards SEES): Full Proposal Deadline D... http://t.co/IG3naAFs
8                                                     When children learn to walk, their language improves dramatically http://t.co/FGYXSKu2
  favorited replyToSN             created truncated replyToSID
1     FALSE        NA 2013-02-05 01:43:45     FALSE         NA
2     FALSE        NA 2013-02-04 19:30:40     FALSE         NA
3     FALSE        NA 2013-02-04 18:01:33     FALSE         NA
4     FALSE        NA 2013-02-04 13:55:46     FALSE         NA
5     FALSE        NA 2013-02-04 13:01:51     FALSE         NA
6     FALSE        NA 2013-02-02 17:19:30     FALSE         NA
7     FALSE        NA 2013-02-02 14:25:15     FALSE         NA
8     FALSE        NA 2013-02-02 14:02:11     FALSE         NA
                  id replyToUID
1 298607815617036288         NA
2 298513923307630592         NA
3 298491499958644736         NA
4 298429645580288000         NA
5 298416076012785666         NA
6 297756138433290240         NA
7 297712287521841156         NA
8 297706485608218624         NA
                                                     statusSource
1 <a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>
2 <a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>
3 <a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>
4 <a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>
5 <a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>
6 <a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>
7 <a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>
8 <a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>
  screenName
1        NSF
2        NSF
3        NSF
4        NSF
5        NSF
6        NSF
7        NSF
8        NSF

      

+3


source


is there an option in the usertimeline function with which we can limit tweets according to the date range



0


source







All Articles