Twitter Streaming API - combine two predicates - twitter

I'd like my Twitter Streaming API to catch all tweets mentioned using some #HashTag within the USA. However, if I use the filter.json service specifying location= &track=, then I get the collective OR. I believe I read somewhere on Stack Overflow that it's by design, but I don't still have that reference.
Is it possible to combine those using AND?

You can't have the API deliver only tweets that match both conditions (AND), but you can collect tweets for either condition (OR), and then only use or save the tweets that match both conditions.

Related

Bluemix - Use Insights for Twitter API to query if a topic is trendy

I'm implementing a sorting algorithm and I want to query the Insights for Twitter API in order to find if a topic is trendy in comparison to another topic.
As far as I've investigated, there is a Count API Operation which will return the number of Tweets based on a given query. Therefore I could query how many Tweets have the particular "keyword" in their body and then compare it to other different keywords to establish an order.
Is there is a more direct query to know if a keyword is trendy?
Your approach using the /api/v1/messages/count endpoint looks like the right one when working with the Insights for Twitter API.
I guess you could also use the posted query parameter to build trending charts over time for your different keywords.

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.

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

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

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

Accessing Twitter historic data in near-past

Is it possible to access historic Twitter data?
I want to write a function that accesses tweets which match certain keywords, like the FilterStream in the Twitter streaming API, but can access tweets which have been created historically.
No it is not.
All you can do, is use search method to get recent matching tweets. (little amount if keywords are unpopular)
Or connect to streaming API and wait (in little while you will have historic tweets)

Resources