Twitter api (Twitter4j). How to get US tweets? - twitter

I'm trying to get random stream US tweets by using twitter4j, but it seems there is no way I can do that.
I decided to use streaming api, because it looks like it suits for my purposes, but the thing is. I can get random tweets, using method sample(). But it returns random tweets without any ability to filter US tweets.
So I used filter method without any success, because I have to set track words and it's not actually what I need.
I tried to use not stream api and it seems that it's possible to reach my purpose, but it's bloody hell.
Does anyone know how to subscribe for US tweets in English by using stream twitter api?

Why don't you use filter mechanism in the streamin api? There is an optional parameter that you can specifically set the coordinated wherever you want, then you will be getting only the tweets determined by these coordinates.
You can have a look at following links for further info:
https://dev.twitter.com/docs/api/1.1/post/statuses/filter
https://dev.twitter.com/docs/streaming-apis/parameters#locations
However, there is no way to filter tweets in terms of language yet in Streaming API, but search API has that functionality.

With Search API, if you can live with omitting Alaska/Hawaii and including Toronto you could go with something like (geocode:"41.2,-113.6,1000km" OR geocode:"38.1,-88.3,1600km"). That gives this sort of coverage:
Or just create longer boolean that does what you want..

Related

YT search API to search for Arabic speaking channels locally in Israel

How can I retrieve all Arabic speaking channels locally in Israel.
Using the API explorer, I don't see such an option.
Which fields are mandatory for search to call the search API?
Is there any way to fulfill this task?
Update:
API Explorer
I couldn't get results
There are lots of parameters in the API v3 Docs for Search that you can play around with, some in particular you might find helpful are:
location
locationRadius
regionCode
relevanceLanguage
and you'll need to set type = "channel" to return only channels.
The only mandatory parameter is part which is what data you want returned from your results. For this search call, you only have one option for part, which is "snippet".
This is the only way to do it simply within your multiple parameters, and it will take 100 quota per search, assuming you have an API key already.
If you press 'Try This API' on the right, it'll even give you code snippets you can copy in a variety of languages, since you didn't specify one in the prompt.
Depending on the language, a call could look like the following:
GET https://youtube.googleapis.com/youtube/v3/search?part=snippet&location=Israel&regionCode=IL&relevanceLanguage=ar&type=channel&key=[YOUR_API_KEY] HTTP/1.1

twitter/tweepy filter tweets that start with a given string

I'm using tweepy stream api now.
I can filter the keyword use the stream.fileter(track=[]) method.
I also want to filter the tweets that starts with a given string.
But he method stream.filter(track=['H']) won't match the tweet 'Hello'
Can i do that and how to do it?
Irnzcig is correct, that kind of restrictions aren't available through twitter Streaming API. What you can do is open a connection to receive all the allowed tweets and filter yourself the ones that start with H
To be more specific, however, Streaming API request parameters is what you're looking for. The link provided in the comment is for the Rest API, while they operate on somewhat similar query input they're vastly different.

Get tweet count of shares for multiple URLs with one request

I know how to get the tweet count of shares for one URL with the following request:
https://cdn.api.twitter.com/1/urls/count.json?url=[URL]
What I don't know is how to get the tweet count of shares for multiple URLs with just one request, maybe something like this:
cdn.api.twitter.com/1/urls/count.json?url=[URL1,URL2,URL3,...]
Facebook already has this functionality:
graph.facebook.com/?ids=[URL1,URL2,URL3,...]
I was wondering if Twitter has this as well.
I don't think is is supported.
Also this URL is not supposed to be available for the public and you shouldn't use it, especially since Twitter plans to shut it down in the near future (this month, I think).
You should look into the the Twitter REST and Streaming APIs instead.
https://dev.twitter.com/streaming/overview
https://dev.twitter.com/rest/public
Twitter says one of these should be used, these are officially supported.
But so far, I haven't found a way to easily query the number of tweets for a URL using these APIs though.

How should I get all the tweets of an specific hashtag?

I'm trying to develop some code in order to get all the tweets that were generated with certain hashtags, then parse them and finally analyse them. I believe I've already thought and solve the last two parts of this but I'm having some trouble with the first one. I've already read the Twitter Search API documentation but I haven't realised yet how to do this. Can anyone help me?
If you want to retrieve the tweets sent recently, you should use the search/tweets endpoint of twitter' REST API, and mention the hashtag inside q parameter
In case you want to listen to tweets containing the hashtag and receive them in real time, then twitter's streaming API is what you should use (statuses/filter endPoint).
Have a look at the documentation on twitter's website, there's also plenty of information on how to do this all around the web.

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