Get my Nth tweet via twitter API - twitter

Looking at the Twitter API, I'm struggling to see how I could get my Nth tweet. I know there is a maximum number we can go back (something like 3200 latest tweets or so), but I'd like to access a specific tweet that I know the N of (i.e. it was my 789th tweet (note that it really wasn't that specific N)).
Thank you!

You can't. The tweet doesn't contain information on its number in stream.
All you can do is count back: you know your current tweet number (statuses_count) and just count backwards in statuses/user_timeline (not too hard with pagination, but they re going to disable it soon).

Related

How to get total number of tweets for a particular keyword search through twitter api?

I am building a simple application where I am searching for tweets related to keywords through twitter apis. Now the API restricts the result to default 15 and maximum 100. I want to know atleast how many total tweets are there for that keyword. I dont want to continue fetching till the results end to get the total count. Is there a simple way without going through the above exercise ?
Thanks in advance.

What is the best approach to working out if I have retweeted a tweet from another user, via the Twitter API?

So, I am currently working on an application that allows me to search journalists and view their contact details including, among other things, their latest tweets.
Calling the Twitter API is no problem at all, and I have a list of tweets for the current journo showing up fine. However, I am trying to decide the best approach to seeing if I (the user logged into our application) have retweeted any of the journo's tweets, so that I can display the tweet as having been retweeted.
Looking at the API documentation, I am looking into the following options:
1 - Use /statuses/retweeted_by_me to get the list of tweets that I
have retweeted, specifying max_id to be the highest id from the
list of tweets for the journo I am looking at. What I am not sure of
here is if the max_id is going to limit by the max id of my tweets or
the max id of the retweeted tweets.
2 - Use /statuses/:id/retweeted_by for each of the journo's tweets to
get a list of all the users who have retweeted that tweet and to check to
see if my user is in the returned list of users. Downfalls of this is that there
could be thousands of retweeters and I can only return a maximum of
100 at a time. That could mean a lot of requests just to find if I
retweeted one tweet. This also means that I need to do this for each
of the journo's tweets as opposed to getting the list of all my
rewteets above.
3 - Use /statuses/retweets/:id to get a list of the retweets for
each of the journo's tweets. This option has the same limitations as
#2.
I'm currently leaning towards #1, however, I'm not sure as yet if this will work. I need to do some more investigation. In the mean time, my question to you is:
What is the best approach to working out if I have retweeted a tweet from another user?
Ok, so I must have been having a brain fart moment when looking into this yesterday. It occurred to me this morning that you can simply make an authenticated call to /statuses/user_timeline which will set the retweeted property to true if you have retweeted that tweet.
Simples.

Pulling large number of tweets by id

I have a list of 5500 tweet ids. For each tweet id, I'm downloading the associated tweet text. The ids are non-sequential and from many different users.
The only API option I see for pulling a specific tweet is GET statuses/show/:id.
That gives only a tweet at a time. With rate limiting of 350 API calls / hr, that means ~16 hrs to download the data.
Is there an API call or better technique that I'm missing?
You can buy tweets from GNIP.
No. I'm afraid none. There's no way to bypass twitters 350 API Calls per hour for authenticated users.
As far as I understood, Twitter API has an end point to fetch up to 100 tweets per request. You can find the details at: https://dev.twitter.com/rest/reference/get/statuses/lookup
I use tweepy's statuses_lookup method: http://tweepy.readthedocs.org/en/v3.1.0/api.html#timeline-methods So, you can retrieve tweets much faster than requesting one tweet at a time.

How to get a list of all retweeters in Twitter?

I have seen numerous companies doing like Twitter lotteries where users got to retweet their tweet and then one of retweeters will get the prize or whatever.
I was wondering now how do they get the list of all retweeters or pick the winner?
I checked Twitter API and found only this thing: GET statuses/retweets/:id but it returns maximum of 100 retweeters. Is that the only way?
It looks likes there's a couple services out there doing almost exactly this. A quick google pulls up http://onekontest.com/ and there's a few other Twitter contest services, but they all seem to be different levels of broken since they haven't kept up with changes to the API.
As far as the Twitter API itself is concerned, if you were expecting more than 100 responses, I think using GET statuses/mentions makes the most sense. That API call returns any mentions of a user, and you can pass the flag include_rts to include any retweets of your tweets. Then, if you wanted to list RTs of a specific tweet, you could check the in_reply_to_status_id field in the returned data to see if it matches the original tweet ID. This API call only returns the last 800 status, 200 at a time, so if you expect a bunch of data, you would need to poll the API repeatedly over time to get all the tweets. I imagine services like favstar are doing exactly this, just on a larger scale.
If you're actually looking for code to do something like this, I wrote a sinatra app called twitter-rss-digest which handles querying Twitter over time to track different sorts of queries. It's pretty rough, and doesn't quite handle this specifically, but it might point you in the right direction if you want to code something.
The Twitter API has an endpoint that returns up to 100 retweeter IDs for a given tweet.
Note that for historical reasons, that endpoint only returns up to 100 results and the documentation about the cursor is useless. Twitter refused to fix the situation.
2013 note
That said, the first thread on the Developers site that surfaced in a quick google has #episod, a Twitter employee saying:
You can't likely get to all of them. The data is spread out. Your best bet is to use the REST API to determine many of the users who performed the retweet, but the data will still be constrained.
It's easiest to track retweets as they happen rather than try to find them from the past. Use the Streaming API for that.
I like muffinista's method, but I think if you want a 100% complete list of retweets, simply enable the retweet email notifications and write a script that polls the email box for those matching the subject "retweeted one of your Tweets!" and put the data into a table. Do this right from the start.
The site https://twren.ch/ enlists all the retweeters for a given tweet (note that it only enlists retweeters who are direct followers of the source tweeter.) Nevertheless its probably the only public source available.

Get first tweet of a given day

Hi all
I am new to twitter API.. So my question may be a trivial one..
I am developing a new twitter widget, in which I want to get the first tweet for a given hashtag on a particular date.
say first tweet for #xyz hashtag tweeted on 12-08-10.
so far through googling and api doc I found rpp * page max = 1500.. if totaltweet for a given day is 2000 how can I retrieve last 500 tweets..
I have a few questions?
1. Is this for any hashtag that a user might request on the fly, or a set of hashtags that generally remain the same?
If it is a set of tags that stays the same for a while, roughly how many tags are there?
When you say a particular date, how far back in time are you going?
There are two standard ways to get tweets for a hashtag. You can use search, which goes back around 7 days or 1,500 tweets. For an active tag, that may only be a day or two. You can use the streaming API, but that doesn't go back, it just starts tracking from the moment you start making the request. The streaming API can track up to 400 hashtags without getting approval for a higher rate. The search API is limited to 10 to 20 hashtags per query.
If you answer questions 1-3, I can suggest a path to getting what you want.

Resources