Twitter API: How to get user's tweets from a timeframe? - twitter

I can't quite believe this, but seems there's no way to get tweets from a particular user from a particular timeframe. Is this true? is there a way around this?
Thanks in advance.
Johnny

Check out this listing of Twitter resources for retrieving historical data. It looks like Tweetbird is the top with Searchastic getting good reviews, but it's shutdown now.
http://blog.tweetsmarter.com/twitter-search/10-ways-and-20-features-for-searching-old-tweets/
There is also a site called Snapbird that queries old tweets. They also have an API on Github that circumvents the 10 day search limit. You can of course use any API method to get user tweets.
https://github.com/remy/snapbird
You can also use Twitter's own since and until operator for timeframes but the capacity of historical data is limited, so it is recommended to use the resources listed instead.
example:
https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&inc‌​lude_rts=true&screen_name={screen_name}&since:2011-11-01&until:2011-11-06

Related

looking for twitter api create favorite rate limit

I tried to find information on the maximum number of tweets/statuses you can favor using the twitter api but couldn't find any information.
This is the post to use https://dev.twitter.com/docs/api/1.1/post/favorites/create
Does anyone know the limit?
It's not precised but experimentally, it looks like around 1000 per day.
Supposedly there isn't one but I've received a message stating this recently.
It's great that you like so many updates, but we only allow so many
updates to be marked as a favorite per day. (More info can be found
here
http://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following)

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.

Does the Twitter API allow filtering by username AND hashtag?

Can I get all the tweets of a particular user, in which a particular hashtag is used?
I could just get the past 100 tweets then filter them on my end, but it would be much more convenient if Twitter could do the filtering on their end.
Is this possible?
Twitter's Advanced Search lets you construct the query you desire. Unfortunately, search results only seem to be for tweets posted within the past 24 hours or so right now; might just be a temporary limitation, not sure.
In any case, your request URL might look something like this (note the JSON and Atom types):
http://search.twitter.com/search?q=%23HASHTAG+from:USERNAME
http://search.twitter.com/search.json?q=%23HASHTAG+from:USERNAME
http://search.twitter.com/search.atom?q=%23HASHTAG+from:USERNAME
But with the current timeframe limitation, it's not very practical.
I am reading the twitter documentation and they say right now it will include only 6-9 days of tweets. Link https://dev.twitter.com/docs/using-search
To do this search against v1.1 of Twitter's API (which requires OAuth), you'd issue a GET request to the a URL structured like:
https://api.twitter.com/1.1/search/tweets.json?q=from:whitehouse+#sotu
See their Search API's "How to build a query" section. You'll be constrained to tweets over the last 7 days, though.

How to crawl retweets of a certain user?

I studied the Twitter API Documentation today. Only find that we could use "Twitter REST API Method: statuses user_timeline" to acquire statuses of a certain user. Retweets are stripped out of the user_timeline for backwards compatibility reasons. If I want retweets included, API Documentation recommend "statuses retweeted_by_me", but retweeted_by_me cannot return the retweets by other users.
I think maybe we can analyse the twitter webpage of a certain user to get his retweets. However is there any elegant way to crawl retweets of a certain user?
Thanks in advance!
This was addressed recently by the Twitter devs. You can now add a include_rts=true to your call to user_timeline. See the full discussion here: http://groups.google.com/group/twitter-development-talk/browse_thread/thread/7a4be385ff549ed0
You want to use the retweeted_to_me API call and then create a union with user_timeline and sort by datetime. It's a little annoying that they don't mix the stream for you.
Call statuses/user_timeline for the specific user then for each status you will have to call either statuses/id/retweeted_by or statuses/retweets.
http://apiwiki.twitter.com/Twitter-REST-API-Method:-GET-statuses-id-retweeted_by
http://apiwiki.twitter.com/Twitter-REST-API-Method:-statuses-retweets
You have to manually use GET statuses/retweets/:id for every Tweet from the use_timeline.

Get follower count on Twitter API search results

What I'm trying to do is pull some search results, and sort them by users.
Right now I'm using
$to->OAuthRequest('http://search.twitter.com/search.json', array('q' => 'search-term'), 'GET');
to get the results, but I can't actually get information about the user like follower_count, etc. so I though I'd take each result's user_id, and run it through http://twitter.com/users/show.xml to get the rest of the information.
The problem is, if I get 50 results that way, that's 50 API calls, which is 1/3 of the hourly limit...
Is there a better way to do this?
Update:
I have requested whitelisting, and the guys at Twitter told me I should instead use the new Streaming API.
This kinda sucks since it's in Alpha testing, and the documentation is unclear, but the concept looks cool, and the limits are different than the regular API. Gonna dive into it later.
Only reliable user information you can get from twitter search results are username (from_user) and profile image url. If you want more information, you will have to call the users/show method for each user. There is no workaround or better way(that I'm aware of).
You will have to Cache user information and request whitelisting.

Resources