I want to get all retweets, that similar to current retweet.
What I mean:
If someone makes retweet, I want to take his tweet id (retweet id) and take all retweets of original tweet, that user retweet.
So: original tweet -> user_retweet_id
get statuses/retweets/user_retweet_id.json
/*as statuses/retweets/original_tweet_id*/
Is it possible?
P.S: I ask it because if I took general information about retweet (user_retweet_id), I get an information about original tweet (retweet_count), but I can't get retweets from it for original tweet.
As far as I know there is no information for getting retweet of a retweet, as essentially you are retweeting the original post. Just retweet an already existing retweet and you will see that you will actually retweeted the original tweet without leaving any mark about the intermediate step.
There's no direct method for that but what you can do is
Extract main username of user who actually posted that tweet
Extract his timeline using twitter.showTimeline()
Then find your tweet using String matching
This will give you original tweet ID
Then you can find most 100 recent retweets using that oiginal tweet ID
I am using twitter4j for this
Related
I'm trying to use the Twitter API: GET statuses/retweets/:id
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-retweets-id
It doesn't seem like the API returns the time a Tweet was retweeted. It only shows when it was created. Is this true? And if so, is there any other way of being able to retrieve the retweet timestamp?
From Introduction to Tweet JSON:
If you are working with a Retweet object, then that object will contain two Tweet objects, complete with two User objects. The Tweet that was Retweeted is referred to as the 'original' Tweet and is displayed under the 'retweeted_status' key. If a Retweet gets Retweeted, the 'retweet_status' will still point to the original Tweet, meaning the intermediate Retweet is not included.
The top-level created_at attribute should be the time of the retweet that you're looking for. The original tweet is embedded inside the retweet object as the retweeted_status and it has its own (earlier) timestamp.
I want to get all the 'retweets with comments' of a tweet.
Here are few things I noticed with twitter api
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'
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?
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.
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
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.
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.
Twitter has recently implemented an automatic way of quoting tweets. It basically extracts an url from a tweet and shows it embedded within your tweet.
My problem is: how do I 'retweet with a comment' without showing the original tweet URL via API?
Retweeting from the website makes the RT look like this .
But when I'm manually prepending a tweet url to my tweet, it looks like this .
notice the literal url.
your tweet has a quoted_status, just put the tweet url as attachment_url args, e.g.
client.update('cool', attachment_url: 'https://twitter.com/emorima/status/1061581991798169600')
it's ruby code with twitter gem
My understanding is that you are achieving the closest solution that Twitter API offers. This thread talks about doing the following:
do a status update, with the 'status' field containing the text of the original tweet, followed by the link to the original tweet. The 'in_reply_to_status_id' field should not be set. This action does not result in the "retweet count" being increased.
do a retweet, which will increase the retweet count.
Based on lfx_cool's answer, I was able to achieve it with this:
statuses/update
post('https://api.twitter.com/1.1/statuses/update.json', {
status:'Some comment', attachment_url:`https://twitter.com/${user.screen_name}/status/${id_str}`,
});
I have found this question. However I think this has changed on API version 1.1.
If I use the search/tweets method, how can I see if the tweet is a RT?
I see that the retweeted field always returns false. Is there another field I can use for this answer?
If it's a retweet, the tweet will contain a property named retweeted_status. To be complete, retweeted_status will not appear if the tweet is not a retweet. More info at: Tweets.
By simply checking the property name
"retweeted_status"
if you does not find then it's not RT.
As #Joe Mayo said, check for the retweeted_status key on the status object.
I have an example that is not caught by #Apoorv Ashutosh's suggestion.
See: https://twitter.com/gppvt/status/474162466776449024 this will redirect (because it is a retweet) to the original tweet. However if you get this tweet through the twitter API, it has retweeted_status. Notice the text does not contain "RT".
The retweeted field is false if the retweet is not done using the retweet button but rahter via RT, so in such a case, just search the "text" field of all tweets for this pattern
RT #
This pattern can be of help, but I don't think there is any other function for this.
The retweeted_status property will exist if the received tweet was retweeted, else you will get the AttributeError error. In the case, you want to get rid of retweeted tweets:
def on_status(self, status):
try:
print "Retweeted ************* \n" + str(status.retweeted_status)
return
except AttributeError:
print "there is no attribut with name retweeted_status"
Just to add a bit more. (using twitter gem (ruby language))
You can check if its a retweet by checking the tweet and then getting what you need from the retweeted_status hash
t = client.status(#########) #function that obtains tweet based on ID where # = tweet ID
puts t.retweeted_status? # returns true or false
t.retweeted_status # returns the actual hash for that
As everyone else has mentioned, you can check to see if the retweeted_status property exists in the response subfield for that Tweet.
However, per the current version of the API, every Tweet object has the field retweeted that stores a boolean value (True or False) that will tell you if a Tweet has been retweeted.
Make sure your "re-tweet" is not actually a quote of an another tweet. In this case, I had to use the quoted_status field to get the original tweet, rather than the retweeted_status one.
To the ones who are using Hydrator1 and relying on its CSV export of the hydrated JSONL file: you can check reweet_id (no it's not a typo in version 0.0.12), and if it's NA then it's an original tweet as I found.
original_twitter_tweets = twitter_csv_data %>% filter(is.na(reweet_id))
I've noticed that retweets are distinguished from regular tweets by the line "RT #..."
The Python code following can be used to identify them:
tweettext = str( tweet.text.lower())
if tweettext.startswith("rt #") == True:
print(tweet.id)
Tweet object is the tweet variable.
Tweepy is another tool you may use to manage the Twitter API more easily.
May I know how do I get latest tweet by specific user and specific hashtag
On twitter GET Search no parameters option for the username or userid
Let's say I want to search tweet from username stackoverflow with #php hashtag.
You would have to custom code the second part.
Use https://dev.twitter.com/docs/api/1/get/statuses/user_timeline - to get the latest tweets from a specific user.
Write Code to search within the response Object of (1) with the hashtag (search-key).