-
Notifications
You must be signed in to change notification settings - Fork 7
/
Main.cs
68 lines (53 loc) · 1.64 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Example setup script for Streamer
using System;
using Streamer;
using System.Threading;
class MainClass
{
static TwitterAccess access;
public static void Main ( string[] args )
{
// Create twitteraccess object
access = new TwitterAccess();
// Request authorisation key
access.GetOAuthURL( OnReceiveAuthURL );
// Get all tweets with a location tag
QueryLocations world = new QueryLocations( new Coordinates( -180f, -90f ), new Coordinates( 180f, 90f ) );
access.AddQueryParameter( world );
// and with the word "bieber" in them
access.AddQueryParameter( new QueryTrack( "bieber" ) );
}
static void OnReceiveAuthURL( string url )
{
// redirect usert to given URL to authorise this app
System.Diagnostics.Process.Start ( url );
Console.WriteLine ( "Please enter passcode from authorisation URL: " );
string passcode = "";
int testParse = 0;
passcode = Console.ReadLine();
while ( !int.TryParse ( passcode, out testParse ) )
{
Console.WriteLine ( "Sorry, invalid passcode, please re-enter: " );
passcode = Console.ReadLine();
}
// use given passcode to get signing pair for all requests
access.GetUserTokens ( passcode );
while ( !access.IsOAuthed () )
{
Thread.Sleep( 500 );
Console.Write ( "." );
}
Console.WriteLine ( "Authorised...connecting..." );
// Is authorised, can now connect
access.Connect ( false );
while ( true )
{
if ( access.tweets.Count > 0 )
{
Tweet newTweet = access.tweets.Dequeue();
Console.WriteLine( newTweet.userName + ": " + newTweet.status );
}
}
// SHOULD ALWAYS CALL DISCONNECT on access object. THIS DOESN"T!!!
}
}