Geeks With Blogs
Max's Blog .NET, Windows Phone, SQL Server and other exciting stuff

In this post, we will get ourselves familiar with one of the popular Twitter API – Twitterizer & the famous Facebook SDK which was recently released by Microsoft. We will be using them in quite few of our up coming project will be doing in the near future. Go to these pages and make sure you download the packages and have the DLLs ready.

“Twitter”izer

This is very famous .Net library to enable easy communication with Twitter. The official Google Code page for this is - http://code.google.com/p/twitterizer/ and has got very good articles on how to get your started.

You can create a Console application or whatever to test the following out.

To use this library, you need to right on the project in VS and then say add reference and browse to the DLL you download from the Twitterizer page. Once you’ve done, you can use the following Using statement to enable use of this library in the code.

 
using Twitterizer.Framework;

Then you need to create an instance of Twitter, passing the username and password as the two parameters.

Twitter t = new Twitter(twitUsername, twitPassword);

Now to get the time line for this user, use the following line.

TwitterStatusCollection timeline = t.Status.UserTimeline();

Now that you’ve got a list, you can merrily iterate through this to get each of the status updates and the details pertaining to each one of them. I’ve used only the status text and the date, you can get more like ID, user id, etc… Just refer the documentation and you should be able to see more.

foreach (TwitterStatus status in timeline)
{
     textBox3.Text += (status.Text + " " + status.Created.ToLongDateString() + "\n\n");
}
 

You can set the status of the current user using

t.Status.Update(“http://geekswithblogs.net/maxonweb”);

This would be sufficient for us to help us look into the WPF application. In our Silverlight and ASP.NET MVC application we’ll use the Twitterizer library more.

 

Facebook SDK

First of all to use the Facebook SDK, you would need a API Key from Facebook, this is fairly very simple, the step are given very clearly in the facebook developer wiki site here.

FBAPISetup

You can download help documentation from here. This page also has some cool video to help you get started. Some WPF related help is available here. Just go though all of them and get yourself familiar with the Facebook SDK.

Similar to what we did for Twitterizer, add reference to Facebook.dll and Facebook.Winforms.dll. Then, use the following using statements atop the code behind file.

using Facebook;
using Facebook.Schema;
using Facebook.Session;
using Facebook.Winforms.Components;
using Facebook.Rest;
using Facebook.BindingHelper;

Just instantiate DesktopSession and API of Facebook.

        DesktopSession session;
        Api api;

Once you have them in place, have your API key in a string variable, like

string api_key = "sdfgsdfgsdfgsdfg1d32d26fe2361d5fc723";

Then to create a session, for us to interact with Facebook,

 session = new DesktopSession(api_key, null, null, true, new List<Enums.ExtendedPermissions>() 
  { 
   Enums.ExtendedPermissions.read_stream, Enums.ExtendedPermissions.publish_stream 
  });
 session.Login();
 api = new Api(session);

When you run the application, the bit of code above is responsible for popping a small windows which asks you to login to your facebook account and asks for your permission to allow access the application to your account.

FBLogin

Once you login, it will ask you to allow access and etc… approve them all.

FBAccess

Now to get your latest facebook status, use the following statement

string status = api.Status.Get().First().message;

Now to set your status, use this one

api.Status.Set("Testing 1, 2, 3.....");

But pretty much what we’ve covered here should be enough for our WPF application that we will be developing in the next few weeks.

Please put your questions as feedback to this post.

Posted on Wednesday, January 13, 2010 10:48 PM General , WPF | Back to top


Comments on this post: Twitter API & Facebook SDK Overview

# re: Twitter API & Facebook SDK Overview
Requesting Gravatar...
Hi im wondering if you can help me, i have added the twitter library and using Twitterizer.Framework; but i keep getting an error for the .Status bit? thanks in advance. Hannah
Left by Hannah on Jan 29, 2010 2:19 AM

# re: Twitter API & Facebook SDK Overview
Requesting Gravatar...
Hi Hannah,

If you used the same code as in this post, then the reason for an error might be wrong password. Give it another.

Cheers,
Max
Left by Max on Jan 30, 2010 12:58 PM

# re: Twitter API & Facebook SDK Overview
Requesting Gravatar...
I have referenced the twitterizer2.dll and followed the example above , but when typing using twitterizer. it only gives the option of using twitterizer.core ( no framework )
then the method twitter is not available in the example you give above , has version 2 made the example above redundant or am i doing something wrong
Left by tim on Apr 27, 2010 11:12 PM

# @Tim re: Twitter API & Facebook SDK Overview
Requesting Gravatar...
Hi Tim,

I used an old version of Twitterizer and apparently lot of things have changed since then. Anyways here is the copy of the version that I used.

http://cid-397644e8d28e79c8.skydrive.live.com/embedicon.aspx/.Public/Twitterizer.Framework.dll

Let me know if you still have any issues.

Cheers,

Max
Left by Max on Apr 29, 2010 10:01 PM

# re: Twitter API & Facebook SDK Overview
Requesting Gravatar...
Pls i need help i want to create a simple application in ASP.net that will automatically sign up new users with twitter and facebook without visiting facebook or twitter site. thank you..
Left by Fego Ogwara on Sep 22, 2011 11:54 PM

# re: Twitter API & Facebook SDK Overview
Requesting Gravatar...
I have developed twitter and facebook on my application, both working fine. But issue is if I logout Twitter and facebook, I can still tweet from twitter in my application but in face book it required for login. can any one explain the reason?
Left by Lakshman Kumar on Nov 09, 2011 10:15 PM

# re: Twitter API & Facebook SDK Overview
Requesting Gravatar...
Hi
Dear Programmer I want to make an application website in which i want to use all the services of facebook and twitter from my website.... does this possible???

please help me.....
Left by shams on Feb 02, 2012 10:46 PM

Your comment:
 (will show your gravatar)


Copyright © Max | Powered by: GeeksWithBlogs.net