So, yesterday (June 11, 2013) we published an minor aesthetic update to our website. Shortly after publishing the update, we noticed the twitter feed on our homepage wasn’t working. We initially thought it was caused by the update, but it turns out that Twitter’s API 1.0 was ‘retired’ and version 1.1 of the API was introduced.
The new API requires that all requests be authorized (via OAuth) and served over HTTPS. This is similar to, but still more restrictive than, Facebook’s API because not even basic requests for public information can be done without authentication.
The Solution: Twitterizer
First of all, I’d like to say Twitter’s API documentation (and Facebook’s for that matter,) is rather poor. It does attempt to explain different methods that are available but we’re going to focus on the using the Twitterizer method which is a C# library that handles much of the OAUth stuff for you. We chose it because we preferred to use C# in this case instead of some of the other alternatives languages. It is important to note that the Twitterizer example on the API documentation page will not work with the 1.1 (it’s for 1.0). That said, the developer smartly included some hooks to allow it to work with 1.1.
Implementing Twitterizer in 4 Steps
- Download Twitterizer (Visual Studio required). Open the Solution and build the main “Twitterizer2” project. It will produce two dll’s:
- Twitterizer2.dll
- Newtonsoft.Json.dll
- Reference Twitterizer2.dll and Newtonsoft.Json.dll in your project.
- Go to dev.twitter.com and sign in with your twitter account. Once logged in, click the Me button (where sign up used to be) and click My Applications. Create a new application for your website (or whatever project will be consuming the Twitter data,) if one does not already exist. Among other information, it will provide you with the following details you will need for authentication:
- Consumer Key
- Consumer Key Secret
- Access Token
- Access Token Secret
- In your project, enter the following code to retrieve 20 of your most recent Tweets in JSON:
OAuthTokens tokens = new OAuthTokens(); tokens.ConsumerKey = "ConsumerKey"; //<-- replace with yours tokens.ConsumerSecret = "ConsumerKeySecret";//<-- replace with yours tokens.AccessToken = "AccessToken";//<-- replace with yours tokens.AccessTokenSecret = "AccessTokenSecret";//<-- replace with yours //USER TIMELINE (ALL TWEETS) UserTimelineOptions userOptions = new UserTimelineOptions(); userOptions.APIBaseAddress = "https://api.twitter.com/1.1/"; // <-- needed for API 1.1 userOptions.Count = 20; userOptions.UseSSL = true; // <-- needed for API 1.1 userOptions.ScreenName = "Your Twitter Screen/Username";//<-- replace with yours TwitterResponse<TwitterStatusCollection> timeline = TwitterTimeline.UserTimeline(tokens, userOptions);
IMPORTANT! Setting the UseSSL and APIBaseAddress properties to match the values in the example code above is what actually instructs Twitterizer to use API 1.1.
Note that you must replace the token value’s with your own values you got from step #3, and specify your screen/username. Inspecting the timline.ResponseObject property, we can see our 20 tweets in a JSON array. We can now pass that JSON to the front-end via a model (if you’re using an MVC solution), or however meets your needs.
- It is also important to note that there are a plethora of methods available in Twitterizer that you can use to manipulate all sorts of data from the API but all of that is outside the scope of this post. Hopefully this helps you get up and running quickly with version 1.1 of API.
Thanks buddy, it was very good start for me…..:)
No problem! I’m glad I could be of some help.
How to update at API 1.1
Can we have a some working example to download?
Sure, I’ll see if I can put something together.
Hi,
i want to follow user with twitterizer but i have some problems.I use this module but i can’t get “listId” and “OptionalProperties options” values.
TwitterResponse AddMember(OAuthTokens tokens, string ownerUsername, string listId, decimal userIdToAdd, OptionalProperties options)
Thanks,
Hello Fatih, sorry I am not familiar with that particular method and thus, can be of little to no help. You may be able to find some help at http://www.twitterizer.net though.
Please help me send or post tweets using TWITTERIZER .
Please help me how to send or post tweets using TWITTERIZER .
What is it that you’re trying to do? Or, what parts are you having difficulty with?
Twitterizer can be used for C# Silverlight?
Yes, I believe so.
Could you please post source code to send one tweet?.
Thanks.
Pingback: Using Twitter API 1.1 with Twitterizer for C# | dotnetqueries
how about silverlight for Windows Phone ? can i use this library ??
You should be able to although I have not verified this. You may just have to try and give it a go or, go to twitterizer’s website as you may be able to find a definite answer there.
-45.56142506
-46.39093137
0
0
0
2013-08-07T13-33
08
07
2013
33
13
8/7/2013
1:33 PM
637.1
B
you need DLLS for api1.1 from this site https://bitbucket.org/szrsharp/twitterizer-remaked-for-api-1.1/overview
(**OR**)
get the Twitterizer source ( https://github.com/Twitterizer/Twitterizer), and change Twitterizer/Twitterizer2/Core/OptionalProperties.cs file. Specifically this line:
this.APIBaseAddress = “http://api.twitter.com/1/”; change to /1.1/ and recompile.
The twitterizer website leads you to believe it is updated to used API 1.1 but it is NOT!! I wasted over a day debugging this.
Hello Johnny,
You are correct. However, as explained (via comments) in the example code, making use of the UseSSL (set to true) and APIBaseAddress (set to “https://api.twitter.com/1.1/”) properties, is a way to get the existing Twitterizer to work with API 1.1. I’ll update the post to make it a little clearer.
Please Help! How Update Status with Twitterizer2
This definitely got me much more comfortable and have a better understanding of how to use this library. Thank you very much for the tutorial!
Thanks a ton!
Thank you. Worthy material
where will the twitterizer2.dll and netsoft.json.dill file will produce????
The DLL’s should be located in the /Bin/Release (or /Bin/Debug) directory of the project once you build the solution/project.