How to work with Twitter Api v1.1 in windows application C#


#1

I’ve checked that the twitter Api v1.0 is retired and v1.1 is available, I am not able to find any demo on twitter api v1.1 in windows application C#. I want to authenticate the user , get full access to read/ write the tweets and view the timeline of user using twitter api v1.1. Please provide me any demo or steps of code user authenticate such as Tweet Deck application.


#2

var timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
var oauthTimestamp = Convert.ToInt64(timeSpan.TotalSeconds).ToString CultureInfo.InvariantCulture);
var encoding = Encoding.ASCII;
var oauthNonce = Convert.ToBase64String(encoding.GetBytes(DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture)));
var userTimelineUrl = string.Format(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={0}&count={1}”, parameters.ScreenName, parameters.FetchCount); var baseString = string.Format( “&oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}&oauth_timestamp={5}&oauth_token={3}&oauth_version={4}”, consumerKey, oauthNonce, oauthSignatureMethod, accessToken, oauthVersion, oauthTimestamp);
var compositeKey = string.Concat(Uri.EscapeDataString(consumerSecret), “&”, Uri.EscapeDataString(accessTokenSecret)); string oauthSignature;
using (var hasher = new HMACSHA1(encoding.GetBytes(compositeKey))) { oauthSignature = Convert.ToBase64String( hasher.ComputeHash(encoding.GetBytes( string.Concat(“GET&”, Uri.EscapeDataString(userTimelineUrl), Uri.EscapeDataString(baseString))))); }
var authHeader = string.Format( “OAuth oauth_nonce=”{0}", oauth_signature_method="{1}", oauth_consumer_key="{2}", oauth_token="{3}", oauth_signature="{4}", oauth_timestamp="{5}", oauth_version="{6}"",
Uri.EscapeDataString(oauthNonce), Uri.EscapeDataString(oauthSignatureMethod), Uri.EscapeDataString(consumerKey), Uri.EscapeDataString(accessToken),
Uri.EscapeDataString(oauthSignature), Uri.EscapeDataString(oauthTimestamp), Uri.EscapeDataString(oauthVersion)); ServicePointManager.Expect100Continue = false;
var request = WebRequest.Create(userTimelineUrl);
request.Headers.Add(“Authorization”, authHeader);
request.Method = “GET”;
request.ContentType = “application/x-www-form-urlencoded”;
var responseStream = request.GetResponse().GetResponseStream();


#3

Hello,

I am currently working on a C# API that you can find here :

This goal of this project is to provide an API which is very easy to use and to modify.
You can directly use classes from the API like Tweet, User…

Example :

  • Get a User :
    User ladygaga = new User(“ladygaga”, token);
  • Send a Tweet :
    Tweet t = new Tweet(“hello”, token);
    t.Publish();

But you can also use the Token class which allow you to give any query you want and have them being peformed for you. They will send you a Dictionary<string, object> back with the response of your query.

dynamic timeline = token.ExecuteGETQuery(“https://api.twitter.com/1/statuses/home_timeline.json”);
for (int i = 0; i < timeline.Length; ++i)
{
Dictionary<String, object> post = timeline[i];
Console.WriteLine(String.Format("{0} : {1}\n", i, post[“text”]));
}

I hope this helps you.
But if you have any specific need please fell free to ask.

Linvi


#4

hi guys, i need to create a twitter feed on my dashboard of windows form application. cant seem to get it right. i placed a web browser tool in there and it displays the whole twitter website. i just wana show a feed


#5

i want to read the twitter message in windows application c#.