10

I want to get all the 'retweets with comments' of a tweet.

Here are few things I noticed with twitter api

  1. Retweets with comments are treated as tweets. The retweet count does not increase if you add a comment, also the twitter message is "XYZ quoted you instead retweeted you'
  2. You clearly can't use this API endpoint https://dev.twitter.com/rest/reference/post/statuses/retweet/:id

Is there a way to find all the 'tweet/retweet with comment' if you can supply the original Tweet/Id?

codeObserver
  • 6,521
  • 16
  • 76
  • 121

2 Answers2

9

So you're referring to Quoted Tweets (retweet with comments). There is no official method for that from the REST API yet, however, there are couple of ways to do it.

  1. Since all quoted tweets contain the short url to the original one, you can still use in_reply_to_status_id and filter by short url of the original tweet
  2. Search for tweets that contain the field quoted_status_id this can be done either through REST or STREAMING API.

quoted_status_id: This field only surfaces when the Tweet is a quote Tweet. This field contains the integer value Tweet ID of the quoted Tweet.

Leb
  • 15,483
  • 10
  • 56
  • 75
  • Thanks Leb! I am referring to 'Retweets of a tweet with addtional comments added by the user on the retweet' http://mashable.com/2015/04/07/twitter-retweet-comments/ – codeObserver Jul 14 '15 at 00:07
  • Let me know if this clarifies things. – Leb Jul 14 '15 at 01:44
  • Thanks Leb. So sounds like I have to grab all tweets from Twitter and filter the ones based on quoted_status_id and in_reply_to_status_id. This sounds very expensive and not sure if Twitter will allow to give me all tweets. Is there a way that I can 'start' with the orignal tweet/id and then get all the quoted tweets for that? – codeObserver Jul 14 '15 at 21:51
  • @codeObserver you're welcome. That's not the proper way to approach it, like you said Twitter will not allow that. It all depends on the method you're using to access the API, most won't have a way to search by `quoted_status_id` so the general solution would be number 1 from above. If you use `GET search/tweets` and filter tweet content containing the short url of the original tweet then *only* those that match that will count towards your limit which is more practical. It's similiar to filtering for some word you're interested in (i.e. stackoverflow) yields only tweets containing that. – Leb Jul 14 '15 at 23:09
  • "If you use GET search/tweets and filter tweet content" The challenge is what do I search for ? I dont know the users comment text after retweet, so I dont know what to search for. Which means I have to search * 'all' tweets – codeObserver Jul 14 '15 at 23:46
  • You obtain the short url for the original tweet that you're interested in, then use that in the search. The quoted tweets will have that in it. A regular tweet is 140 char, a quoted tweet is 117 chars (140-23) due to the 23 char short url. So you know for a fact it contains that short url. – Leb Jul 15 '15 at 01:03
  • Have to imagine that this change twitter made breaks things for quite a few people. I notice that these comment/quoting RTs dont even get counted at RTs in the twitter web UI. And no endpoint I can find to get the quotes of a given tweet seems tragic...guess there's always Gnip?$$? – mmeyer Sep 30 '15 at 22:38
  • Yep, especially since the [takeover](https://blog.twitter.com/2014/twitter-welcomes-gnip-to-the-flock) – Leb Sep 30 '15 at 23:05
  • Hi, @Leb. I tried to get the short url of retweet with comment under two account. And the urls generated is not the same. Then the first solution might not work. – William Jun 21 '16 at 02:56
0

This isn't easy to accomplish. Here's the brute-force API method to find Quote Tweets.

Take your tweet id, it'll be something like 750176081987014657.

GET search/tweets

Use the Twitter API and search for the tweet.

https://dev.twitter.com/rest/reference/get/search/tweets

The GET request will look something like this:

https://api.twitter.com/1.1/search/tweets.json?q=750176081987014657&count=100

The q "query" argument is the tweet id. I've set the result count argument to the maximum (100).

Authorization

Of course with the Twitter API there's a whole bunch of tricky Authorization header work you have to do as well in order to complete the GET request. That's documented elsewhere and is beyond the scope of this answer.

Results and Conclusion

When you have the JSON results of this GET request, focus on the statuses collection. For each tweet in the collection (otherwise known as a "status"), check if it contains a quoted_status_id field. If it does, and the field value matches your tweet id, the tweet is a quote tweet. If it does not, it is simply a retweet with no added comment. You will also have to deal with iterating through the pagination of results if there are more than 100. That's done by looking for a search_metadata.next_results field and retrieving the next GET query string from it, which will be provided for you.

robbpriestley
  • 3,050
  • 2
  • 24
  • 36