Searching tweets

Apr 13, 2015 at 12:59 PM
Hi linvi,

Please suggest me what kind of api shall i use for getting tweets so that i can get tweet details, the person who has tweeted and able to process them if there are hash tags in it. these tweet shall be real time tweets. ie as soon as the user tweets in my handle i should be able to process them. I am bit confused in between search api and streaming api.

Please help me out.

Thanks in advance

Viswadattu
Apr 13, 2015 at 5:17 PM
Hi,

The difference is quite easy to understand. A stream is an open connection that never closes and listen to a list of events sent from Twitter.
The streams allow you to get up to 1% of the total tweets posted on Twitter. When a tweet has been sent on a stream you cannot go back to get it its gone (apart if you have privileged access).

The search is way different, it allows you to get tweets matching a specific query. The search will not be performed on tweets older than 15 days usually.

There are various other differences but I think you get the global idea of the difference.
In most cases when you are doing real-time, you need to use the Stream option.

Cheers,
Linvi
Apr 14, 2015 at 10:20 AM
Hi linvi,

Consider my scenario of hashtag banking what kind of api should i go with is it search api or streaming api.

please guide me.

Thanks in advance
Viswadattu

Apr 14, 2015 at 10:30 AM
Edited Apr 14, 2015 at 12:03 PM
Your scenario is very vague but anyway. As you said you wanted to get tweets in live I would use the Streaming API with the FilteredStream.
var fs = Stream.CreateFilteredStream();
fs.AddTrack("#myhashtag");
fs.MatchingTweetReceived += (sender, args) =>
{
    var tweet = args.Tweet;
    // Do whatever you want with your tweet
};
fs.StartStreamMatchingAllConditions();
Linvi
Apr 14, 2015 at 11:29 AM
Hi linvi,

These are the two ways to tweets using tweetinvi i am using asp.net web application version .net framework 4.0

First Method using filteredstream

/// <summary>
/// to get the tweets based on the streaming api
/// </summary>
public void getstreamapidata()
{
var requestAccount = Tweetinvi.User.GetFollowers("viswadattu");
var responseAccount = Tweetinvi.User.GetFollowers("dattu_work");
var result = (from p in requestAccount join q in responseAccount on p.Id equals q.Id select p).ToList();
var filteredstream = Stream.CreateFilteredStream();
filteredstream.AddTrack("@viswadattu");
filteredstream.MatchingTweetReceived += (sender, e) => {
foreach (var followers in result)
{
if (e.Tweet.Creator.Id == followers.Id)
{
// save the tweets in the database and process them and give response to the followers
}
}
};//here we can save in the database.
filteredstream.StartStreamMatchingAllConditions();
filteredstream.StopStream();
}

second method using normal search api

public void getTwitterUserData()
{
var searchParameter = Search.CreateTweetSearchParameter("@viswadattu");
var tweets = Search.SearchTweets(searchParameter);

foreach (var item in tweets)
{
if(item.Hashtags.Any())
{
for (int i = 0; i < item.Hashtags.Count; i++)
{
string hashTagText = item.Hashtags[i].Text; // to append the hashtag
}
}
}
}

i request you to please guide me the most effective way for getting tweets without loss of tweets for my scenario from particular twitter handle ie @viswadattu

Thanks in advance

Viswadattu


Apr 15, 2015 at 2:11 AM
Well, the problem is that you want to run a background task on a website.
So basically you need to find a technology allowing you to perform long operation in your server and communicate this information back to your clients.

Usually I would use WebSocket to do that. But your problem is not with Tweetinvi, your problem is about choosing the right technologies to implement what you want to do.

If you want to perform a search you can do it with a classical ASP.NET website.
If you want live information you will need to use a stream and therefore WebSocket.

I hope this makes some sense.

Linvi
Marked as answer by linvi on 4/18/2015 at 4:42 AM
Apr 15, 2015 at 11:17 AM
Edited Apr 15, 2015 at 11:18 AM
thanks for the great guidance you have given me helped me a lot......

Viswadattu