Shafiq Shafiq - 3 months ago 10
R Question

How to get latest news posted on twitter by a website

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?

Answer

I 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 try

userTimeline("ExpressNewsPK")

read more about it at ?userTimeline