Is there a way to get a list of users based on a hashtag they used? - twitter

I want to get a list of users who have used a particular hashtag. Eg. #ManOfSteel.
How can I get a list of the users who are using that hashtag as well as their details (like which city they are tweeting from) using a twitter API or any other means?

Yes, you can. And it's quite simple, really.
According to the documentation:
GET search/tweets: - Returns a collection of relevant Tweets matching a specified query.
Resource URL: https://api.twitter.com/1.1/search/tweets.json
Now if you scroll down on that page, it gives an example of what a query for a tweet returns (I took a screen, sorry about the appalling arrow, it's 10am here and I haven't had my tea yet).
Great! So you know the URL and method (GET) that you need to get your data. As for searching for a hashtag specifically, the query documentation is what you're after.
This is basically as urlencoded string in the GET request like: ?q=#hashtag. Perform the search like that and you'll get back the data above. Then just loop through it, find the user object, and grab the value location key if you want the user's city.
Now, as for a library to interact with the twitter API, you haven't even stated what language you're using. From your profile, you use JAVA I'm guessing. Regardless, checkout the libraries page on the twitter dev site - there's one for JAVA that looks pretty good (and many for other languages too).
If you were using php, this post would be immensely helpful.

Related

Asana: convert user #-tag to API object

I'm parsing the description of tasks for user links (#-tags) that we use to identify different roles on an item. I noticed something weird about the IDs though.
In the notes of a task returned from the API the #-tags are converted to links in the form https://app.asana.com/0/<int_id>/<int_id> which, when visited in the browser, show the user's tasks but when I use that ID to query the API as in https://app.asana.com/api/1.0/users/<int_id> I get a 403 with this response: {"errors":[{"message":"user: Not the correct type"}]} - further investigation showed that the IDs used in the #-tags are different from those used in the API for the same user, even though they both lead to the same page.
My question is are these IDs meant to be opaque or is there a way to convert them to the correct corresponding API IDs (short of browser scraping)?
Unfortunately, it's not possible at this time. In comments and notes (basically, anywhere in Asana that Rich Text is possible), we represent users as the URI to their "My Tasks" page, which is different from their User ID (as you noticed).
We are exploring ways to close this gap, but don't have anything to share at this time. I know that's not super helpful, but I hope it at least helps to have a definitive answer :-(

Displaying tweets from multiple users (similar to Embedded Timelines) without twitter-side user lists

I am new to Twitter and need some tips.
I need to display tweet feed from multiple users on some webpage.
The first thing I stumbled upon is Embedded Timelines. It allows to display tweets from list of users but the gotcha is that those lists should be maintained on Twitter-side (i.e. I cannot specify #qwe and #asd only on my side and get timeline without adding those users into list on Twitter-side).
The thing is that list of users that should be included into timeline is dynamic and managing those lists through Twitter API will probably be painful. Not to mention that my website will probably generate tons of those lists and I feel that I will violate some api quotas sooner or later.
So, my question is - am I stuck with using Embedded Timelines that refer some user list on Twitter-side and managing those lists through, say Twitter REST api, or there is a simplier way to do what I want?
It's pretty simple to display tweets for multiple users.
Links to start with
This post explains some of the search queries you can make
This post is a simple library to make requests to the twitter API that 'just works'
Your Query
Okay, so you want multiple users. The endpoint you're looking at using is the search/tweets one: https://api.twitter.com/1.1/search/tweets.json.
The query string uses :from and you can interpolate multiple froms with AND/OR.
An example query for the GET request:
?q=from:user1+OR+from:user2
Read more about the search API queries here.
Your "over-the-quote" issue
This is something you're going to need to figure out yourself - depending on the number of requests you expect to make, and the twitter imposed limits, maybe some sort of caching or saving information when you hit your limit, and only pull back from the cache whilst you're hitting your limit..

Searching Twitter feeds

I'm looking to take information from Twitter feeds such as removed posts. Is it possible to do this through some sort of string match search by looking for keywords, that is, "this post removed"?
This is for an Arduino project.
It should be. Twitter just turned off their old API, though, so as long as you're willing to get an API key, you should be fine (https://dev.twitter.com). Grab the data with loadBytes or loadStrings called on the API URL and then start walking through the data you got back (http://processing.org/reference/loadStrings_.htm) -- which in the new API will be JSON. You can use a JSON library to turn that into an actual object, but frankly if you want to do text matching, which you do, then there's really no need for Object repacking.

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 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