Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

Edited Unassigned: Some examples of usage in MVC or WebForms applications please? [2266]

$
0
0
Hi,

__Background information:__

I am trying to build a map either using MVC or WebForms that displays all of the geo-tagged tweets being tweeted in real time on the map. I want to use Tweetinvi's Twitter Streaming API functionality to do so.

__The problem:__

Having looked at all of the examples in the Examplinvi folder, they all seem to be for console-based or WinForms applications. Struggling to get my head around how I can access the Streaming API and asynchronously return the streaming result back to the page. I have seen examples using SignalR which enables the server to send data back to the client continuously but I don't know how TweetInvi can be used to do this in a web app. For example this code example is shown in the documentation:

```
// Access the filtered stream
var filteredStream = Stream.CreateFilteredStream();
filteredStream.AddTrack("ladygaga");
filteredStream.MatchingTweetReceived += (sender, args) => { Console.WriteLine(args.Tweet.Text); };
filteredStream.StartStreamMatchingAllConditions();
```

Obviously if this kind of pattern cannot be done with WebForms, that is okay; I am fine with MVC as well. I am struggling to envisage what kind of architectural pattern I need to implement to get this continuous HTTP connection setup. Do I need to setup an asynchronous Controller in my MVC application to continuously send data back to the client?

Sorry if this question is a bit muddled, but I would be eternally grateful if someone could point me in the right direction!
Comments: ** Comment from web user: linvi **

Hi,

I have tried the following code in a hub and it is working perfectly.

``` C#
public class ChatHub : Hub
{
private bool _sessionEnabledThread;
private Thread _thread;
private ISampleStream _sampleStream;

public void StartThreadOperation()
{
TwitterCredentials.SetCredentials("MY_CRED", "MY_CRED", "MY_CRED", "MY_CRED");

_sampleStream = Stream.CreateSampleStream();
_sampleStream.TweetReceived += (sender, args) =>
{
Clients.All.broadcastTweetMessage(args.Tweet.Text);
};

_thread = new Thread(_sampleStream.StartStream);
_thread.Start();
}
}
```

Linvi


Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>