A month ago a build a twitter tool in c# Windows Form Application. I can send tweets and view the hometimeline,friendtimeline and the mentiontimeline. I used the twitterizer dll with the OAuthTokens method, but there is a refresh limit and it is very slow.
Now i want to start a streaming twitter application but i cant find a proper example or documentation for this. I started but i didn’t find the function who can start the stream and but it in a string or textbox. My question is how to get the stream from the hometimeline.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Twitterizer;
using Twitterizer.Streaming;
namespace Twww
{
public partial class Form1 : Form
{
public OAuthTokens tokens = new OAuthTokens();
private string userAgent = null;
public Form1()
{
InitializeComponent();
/* input tokens removed in example code */
tokens.AccessToken = accessToken;
tokens.AccessTokenSecret = accesssecret;
tokens.ConsumerKey = consumerKey;
tokens.ConsumerSecret = consumerSecret;
}
private void Form1_Load(object sender, EventArgs e)
{
Twitterizer.Streaming.UserStreamOptions options = new UserStreamOptions();
OAuthTokens token = new Twitterizer.OAuthTokens ();
TwitterStream stream = new TwitterStream(token, userAgent, options);
}
}
}
I tried to make it work for a user stream, but i get 401 or 403 errors, who says i have no rights
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Twitterizer;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
OAuthTokens tokens = new OAuthTokens();
string consumerKey = "XX";
string consumerSecret = "XX";
string accessToken = "XX";
string accesssecret = "XX";
tokens.AccessToken = accessToken;
tokens.AccessTokenSecret = accesssecret;
tokens.ConsumerKey = consumerKey;
tokens.ConsumerSecret = consumerSecret;
string url = "https://userstream.twitter.com/1.1/user.json?with=followings&replies=all";
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential("XX", "XX");
StreamReader reader = new StreamReader(wc.OpenRead(url));
string line;
while ((line = reader.ReadLine()) != null)
{
dynamic json = JsonConvert.DeserializeObject(line);
if (json.text != null)
{
Console.WriteLine(json.text);
}
}
}
}
}
Check this, you have a very well designed guide of TwitterStream in twitterizer:
http://thewayofcode.wordpress.com/tag/json/