I am using R and I need to retrieve the few most recent posts from a Twitter user (@ExpressNewsPK) using twitteR api. I have created an account and have an access token, etc. I have used the following command to extract the tweets:
setup_twitter_oauth(consumerkey,consumersecret,accesstoken,accesssecret)
express_news_tweets <- searchTwitter("@ExpressNewsPK", n = 10, lang = "en" )
However, the posts that are returned aren’t the most recent ones from this user. Where have I made a mistake?
2
Answers
When you use
searchTwitter()
, you call theTwitter Search API
. Search API only returns a sample history of the tweets.What you really need to do is to call
Twitter Streaming API
. Using it you’ll be able to download tweets in near real time. You can read more about the Streaming API here: https://dev.twitter.com/streaming/overviewI think
searchTwitter
would search with the search string provided (here @ExpressNewsPK). So instead of giving tweets by @ExpressNewsPK it would give tweets which are directed to @ExpressNewsPK.To get tweets from @ExpressNewsPK, you have a function named
userTimeline
which would give tweets from a particular user.So after you are done with
setup_twitter_oauth
, you can tryread more about it at
?userTimeline