Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch queries in twitter api?

Tags:

twitter

I need to run a query that returns a list of users, along with data about those users. Suppose I consider one person and I want to know where all his/her followers are. This query:

http://api.twitter.com/1/followers/ids.json?screen_name={screen_name}

returns a list of user ids of the person's followers. I can then plug each user id into this query:

http://api.twitter.com/1/users/lookup.json?user_id={user_id}

to get information about the user, including location. But that means that if the person has 1000 followers, I would have to call the second query 1000 times. It would be better to do a "join" (as it would be called in SQL), where we could ask for the followers AND their locations, and do this in one query, but I can't see how to do this.

Is this possible? Also, when asking for user lookup, is it possible to specify that you only want one field and not the whole user record (kind of like asking for select single_field instead of select * in SQL)?

like image 304
Joshua Frank Avatar asked Apr 07 '12 01:04

Joshua Frank


People also ask

How do you create a query on Twitter?

How to build a query. The best way to build a query and test if it's valid and will return matched Tweets is to first try it at twitter.com/search. As you get a satisfactory result set, the URL loaded in the browser will contain the proper query syntax that can be reused in the API endpoint.

How do you search multiple keywords on Twitter?

You can enter multiple keywords or phrases by clicking on the tab button, or a comma or by pressing enter. When you want to search for an exact phrase on Twitter through Freshdesk, you should type the phrase within quotes.

How many Tweets can you get from Twitter API?

Note that beyond these limits on the number of requests, the Standard Basic level of access provides up to 500,000 Tweets per month from the recent search and filtered stream endpoints.


1 Answers

You can enumerate multiple user_ids in query. Example:
http://api.twitter.com/1/users/lookup.xml?user_id=351927492,8602462,132533067,16984020,131217651,125764179

But you capped to 100 values (names, ids) per query, so for user with 1000 followers you have to make 10 queries.

Update For 1.1 version of API correct URL would be http://api.twitter.com/1.1/users/lookup.json?user_id=351927492,8602462,132533067,16984020,131217651,125764179

like image 95
om-nom-nom Avatar answered Sep 18 '22 12:09

om-nom-nom