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

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

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 do I search tweets of a given multiple users based on certain criteria using twitter api?

I have list of users
['foo','bar']
I want to search whether they have checked in somewhere or not (using 4sq api)..
So basically, all I am looking for is that whether their tweets contain "\4sq.com\" or not?
I get very confused looking into their api?
Bonus points if the steps can be implemented in python.
Thanks
You have two options for checking a user's tweets:
One option is to look through the tweets in their User Timeline (accessible in Tweepy through api.user_timeline). However, you may have to search through a lot of unrelated Tweets before you come across the one your looking for. Given how many tweets some users have, you might want to only look thorough tweets more recent than a certain date (you can look at the created_at attribute of returned tweets).
The other option is to use the Search API (accessible in Tweepy though 'api.search'). This has the advantage of allowing you specify a search query, giving you relevant tweets. However, you will need to search through the tweets until you find one by the user you're looking for. Again, you might want to limit the date range of tweets that you search through.

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

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

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

Twitter search for anything from a certain source

The Twitter-search features the possibility to search for a source of tweet by using the parameter "source:" (e.g. source:tweetdeck).
If I just search for that it complains about a missing query, but I actually want to search for any tweets from a certain source.
Is that possible?
You need to have some form of criteria, even if it's just 'recent tweets'. To query every single tweet is, I suspect, not possible at all and certainly not within the capabilities of the API.
Note: My mistake - was thinking of one of the REST APIs.

Resources