retweeting using twitteR

246 views Asked by At

Is it possible to retweet a status using the twitteR package (or just R in general)?

For example, if I import a bunch of tweets and I want to retweet one of them:

library(twitteR)

# load ROAuth handshake (authorization to interact with Twitter) and check if connection to twitter is established
load(file = "twitteR_credentials")
registerTwitterOAuth(twitCred)

# search Twitter for 25 tweets containing the term '#twitter' and take the first one
tweets = searchTwitter('#twitter', n=25)
favorite_tweet = tweets[1]

# is there a function that lets me retweet favorite_tweet to my own timeline?

I know you can use the updateStatus function to post a status consisting of text, but is there a similar function which lets you update your status by retweeting another status?

2

There are 2 answers

0
datawookie On

This should do the trick:

updateStatus(favorite_tweet[[1]]$text)

Note that your favorite_tweet is still a list, so it might be slightly better to rather do:

favorite_tweet = tweets[[1]]
updateStatus(favorite_tweet$text)

which gets rid of extraneous indexing.

The key though is that you are wanting to retweet the text content of the tweet, not the tweet object itself.

0
wugology On

I am having this exact same problem trying to make a retweet bot. Python's tweepy and twython don't seem to be playing nice lately, but R is connecting fine to twitter's API. I can updateStatus("hello world!") alright, but when I try to do something like updateStatus(favorite_tweet) as in your example, I get this error:

[1] "Authorization Required"
Error in twInterfaceObj$doAPICall("statuses/update", params = params,  : 
  Error: Authorization Required

Obviously since in the same session I am able to updateStatus("hello world!") something is up. They have my authorization, and it's working just fine.

The best I can figure out is that favorite_tweet is an object of class status. This seems to be preventing updateStatus() from interpreting it as a string that can be retweeted. I tried unlist() and manipulating it with gsub() but haven't found a good solution yet. If I do, I'll let you know (and I hope if you do, you'll let me know).