Twitter API bug - Tweets provides the wrong User_id. Work arounds? - ruby-on-rails

I'm looking for a workaround to this Published Twitter API bug: http://code.google.com/p/twitter-api/issues/detail?id=214
When you fetch tweets, the tweet returns an incorrect User_id. However it does provide you with the correct Screen name.
My Goal is to use the API to do 2 things:
Fetch all the followers of my twitter account, this is trivial with the ruby script:
myfollowers = Twitter.follower_ids("justinzollars") (twitter gem)
corresponding to this api call: https://dev.twitter.com/docs/api/1/get/followers/ids
Save only tweets from an individual user. https://dev.twitter.com/docs/api/1/get/search
The problem is the first api call returns user_ids, and the tweets search call returns from_user_id_str (user_name). I don't want to make tens of thousands of api calls, asking twitter for the user_id of each from_user_id_str that is returned from the tweets search api call.
How can I efficiently solve this problem?

The Search API isn't really the best tool for the job as far as retrieving a specific user's tweets is concerned. You should use the User Timeline for that task, which doesn't suffer the Search API's mismatched user ID issue: https://dev.twitter.com/docs/api/1/get/statuses/user_timeline
If you were using the Search API though, the most efficient pattern for converting screen names in Search to user ids on Twitter would be to use bulk user lookup, which would allow you to convert roughly 100 screen names to fully hydrated user objects (complete with the "real" user id): https://dev.twitter.com/docs/api/1/get/users/lookup

Related

Is there any limit for fetching followers from twitter

Fetching the followers list of a user, but there might be some users that have millions of followers. So are we able to fetch all followers using twitter api.
Presently using users/lookUp api and followersId api to get data.
Yes, there's a limit, around 5k(not exact as Twitter says) for each request.
You can use Twitter 'cursoring' technique as described here https://dev.twitter.com/overview/api/cursoring
The Twitter REST API utilizes a technique called ‘cursoring’ to paginate large result sets. Cursoring separates results into pages (the size of which are defined by the count request parameter) and provides a means to move backwards and forwards through these pages.
Each cursor has previous/next_cursor and other stuff that you can use when sending request. Check out the example provided in official documentation.

How can I search users on Twitter using multiple filters?

There are Twitter platforms like http://www.socialbro.com/ or https://manageflitter.com/ that allow you search users using filters such as genre, country, language, bio, age, profile photo...
How can they find users with these conditions? I didn't find on Twitter API documentation any method for that.
For example, if you look for "marketing" on ManageFlitter it returns us 700k users with that word in their bio. How they are getting that amount? Twitter API only returns 1000 users using search/users method.
I found there are Google commands like [site:twitter.com bio:*keyword -inurl:status] which return every user with a keyword in their bio. Are these platforms using something like this?
There isn't a way to do that with the API, which is limited on every endpoint. The only way to access this much Twitter information is via a data provider. Twitter acquired Gnip, who was one of these companies and there are others. You can subscribe to their service and get the entire history of tweets plus other value-added benefit each of them offers. Unlike the API, you'll have to pay, but the trade-off is that you receive better features and service.

Twitter API 1.1: Return all tweets that contain a certain hashtag OR are by a specific user

Is there an API call which will return all the tweets which contain an specific hashtag (#example) and also all the tweets from a certain user (#example)?
Looking for a single API call, that returns a JSON object with both those criteria.
I know I can do with two separate API calls, but I an trying to do this with one. Possibly https://dev.twitter.com/docs/api/1.1/get/search/tweets is the best bet.
When you use multiple terms together, Twitter search performs an AND operation by default. i.e.
https://dev.twitter.com/docs/api/1.1/get/search/tweets.json?q=from%3AJoeMayo%20%23twitterapi
Returns only tweets that are from JoeMayo and contain #twitterapi.
You can experiment with it on Twitter's Search page.
https://api.twitter.com/1.1/search/tweets.json?q=shrmi14
is the one that i used.
Incase you feel issues. refer https://dev.twitter.com/console for generating your own queries..

why do i only see one tweet in the search from API Query?

I'm using the following query:
https://twitter.com/search.json?callback=?&q=from:_adeel&count=5&include_entities=true&include_rts=true
and I would like to see the last 5 tweets from this user. You can see that the user has many more than 2 tweets yet the query only returns 2 tweets. I'm following the twitter search API and I fail to see what I'm doing wrong. I prefer to use the twitter search API because I want to perform the search on the client side without authentication and rate limits.
Do you see what I am doing wrong?
As indicated here in the documentation, the search API is an index of recent tweets, between 6-9 days old. It looks like the other tweets from the user you linked to are just outside this window.
So to summarize - you are not doing anything wrong. This is simply a limitation of the Twitter API.

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.

Resources