How do I properly 'Retweet with a comment' via Twitter's API - twitter

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}`,
});

Related

How to find all 'retweet with comments' for a particular Tweet using API?

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 API: Check if a tweet is a retweet

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.

Twitter API: How to get retweets for retweet?

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

Twitting URLs with # in them and getting their count

The goal here is to be able to "tweet" a link of the format
www.example.com/page.aspx#1, and get the number of "tweets" for that link... Basically, what the out-of-the-box Twitter button does for any normal link.
Reason for this is because the page displays different content based on the ID after the #, so there is a need to count which specific item was "tweeted" and how many times.
I tried passing that URL to the Twitter service to get the count (http://urls.api.twitter.com/1/urls/count.json?url=), but the JSON object I get back only has
{"count":0,"url":"www.example.com/page.aspx/"}.
The link for the Twitter button looks like this (done in JavaScript)
var twtLink = 'http://twitter.com/intent/tweet?url='+encodeURIComponent(twtUrl)+'&counturl='+encodeURIComponent(twtUrl);
Any suggestions would be appreciated.
Thanks!
Twitter actually re-interrupts all URL's with their own custom t.co wrapper. This is good news for your use case. You can use these unique t.co links with the counter API.
If you include the attribute &include_entities=1 to the end of some Twitter REST API calls you get back expanded info including the URL's in the tweets. You will see the original URL as well as the shortened URL version. Pass the shortened URL version into the counter API.

Twitter API - Display all tweets with a certain hashtag?

How would I go about displaying tweets that contain a certain hashtag using the Twitter API? Thanks
I'd also like to know if there is a way to get all tweets from a certain hashtag in a separate file, also the ones that don't show up in your feed anymore. I suppose that's what the earlier question was about, too.
This answer was written in 2010. The API it uses has since been retired. It is kept for historical interest only.
Search for it.
Make sure include_entities is set to true to get hashtag results. See Tweet Entities
Returns 5 mixed results with Twitter.com user IDs plus entities for the term "blue angels":
GET http://search.twitter.com/search.json?q=blue%20angels&rpp=5&include_entities=true&with_twitter_user_id=true&result_type=mixed
UPDATE for v1.1:
Rather than giving q="search_string" give it q="hashtag" in URL encoded form to return results with HASHTAG ONLY. So your query would become:
GET https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames
%23 is URL encoded form of #. Try the link out in your browser and it should work.
You can optimize the query by adding since_id and max_id parameters detailed here. Hope this helps !
Note: Search API is now a OAUTH authenticated call, so please include your access_tokens to the above call
Updated
Twitter Search doc link:
https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html
The answer here worked better for me as it isolates the search on the hashtag, not just returning results that contain the search string. In the answer above you would still need to parse the JSON response to see if the entities.hashtags array is not empty.

Resources