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" ) ); }
public string AuthoriseRequest(string[,] queryParameters, string url, bool useToken = true) { // make nOnce StringBuilder no = new StringBuilder(32); string alphanumeric = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"; System.Random random = new System.Random(); for (int i = 0; i < 32; i++) { no.Append(alphanumeric[random.Next(alphanumeric.Length)]); } // set timestamp string timeStamp = ((int)(System.DateTime.UtcNow - new System.DateTime(1970, 1, 1)).TotalSeconds).ToString(); // sort all the parameters to be signed SortedDictionary <string, string> properties = new SortedDictionary <string, string>(); for (int i = 0; i < queryParameters.GetLength(0); i++) { properties.Add(queryParameters[i, 0], queryParameters[i, 1]); } properties.Add(TwitterAccess.UrlEncode("oauth_consumer_key"), TwitterAccess.UrlEncode(consumerKey)); properties.Add(TwitterAccess.UrlEncode("oauth_nonce"), no.ToString()); properties.Add(TwitterAccess.UrlEncode("oauth_signature_method"), TwitterAccess.UrlEncode(signatureMethod)); properties.Add(TwitterAccess.UrlEncode("oauth_timestamp"), timeStamp); if (useToken) { properties.Add("oauth_token", TwitterAccess.UrlEncode(token)); } properties.Add("oauth_version", TwitterAccess.UrlEncode(version)); // make parameter string StringBuilder parameters = new StringBuilder(); foreach (KeyValuePair <string, string> kv in properties) { parameters.Append(kv.Key + "=" + kv.Value + "&"); } parameters.Remove(parameters.Length - 1, 1); // generate signature string postParameters = "POST&" + TwitterAccess.UrlEncode(url) + "&" + TwitterAccess.UrlEncode(parameters.ToString()); string signature; if (useToken) { signature = SignString(postParameters, TwitterAccess.UrlEncode(consumerSecret) + "&" + TwitterAccess.UrlEncode(tokenSecret)); } else { signature = SignString(postParameters, TwitterAccess.UrlEncode(consumerSecret) + "&"); } properties.Add("oauth_signature", TwitterAccess.UrlEncode(signature)); // construct auth header // oauth_verifier is special case used only when getting new access tokens StringBuilder header = new StringBuilder("OAuth "); foreach (KeyValuePair <string, string> parameter in properties) { if (parameter.Key.StartsWith("oauth") && parameter.Key != "oauth_verifier") { header.Append(parameter.Key); header.Append("=\""); header.Append(parameter.Value); header.Append("\","); } } header.Remove(header.Length - 1, 1); return(header.ToString()); }