Click here to Skip to main content
12,241,814 members (46,743 online)
Click here to Skip to main content
Add your own
alternative version


77 bookmarked

C# Application Integration with Facebook & Twitter with oAuth

, 9 May 2012 Public Domain
Rate this:
Please Sign up or sign in to vote.
This is a very basic level tutorial about authenticating with Facebook and Twitter and setting your status with it.


This articles describes a simple tutorial explaining:

  1. Setting a Facebook status through a C# application
  2. Sending a Tweet through a C# application


Last week i had to do a little proof of concept about integration of Twitter & Facebook with a C# application. All I had to do was post a simple status on users' Facebook wall or post a tweet. What I was surprised after considerable research was the lack of basic tutorials/resources that were available. I did not come across a simple "Hello World" example to get me started. So I had to go through some high level tutorials and extract a basic POC; which iam going to share with the community.

This is my first share, so i would appreciate any suggested improvements . Also I am very much open to any suggestion/corrections. I would love to learn more from some really good developers of the community.

Using the code


Let's start by first doing the Facebook part of this article. 

To set a status on Facebook using your C# application, first of all you will need to create an application by going to the following link:

  • Click on the CREATE NEW APP button.

  • Fill in the required information and click Continue

  • Now your application has been created. There are 2 things that you need to take note of; The App ID & AppSecret. We will be using them later on.


  • Now let us move on to the coding. Make a new Windows Forms Project. We will add a WebBrowser to our main form.
  • The App.config of your project should look something like this:

<?xml version="1.0" encoding="utf-8"?>
    <add key="EnableSqlDependency" value="true" />
    <add key="ApplicationId" value="<YOUR APP ID GOES HERE>" />
    <add key="ApplicationUrl" value="" />
    <add key="ApiKey" value="" />
    <add key="ApplicationSecret" value="<YOUR APP SECRET GOES HERE>" />
    <add key="ExtendedPermissions" value="offline_access" />
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />

  • Now we'll move on to authorizing the application. For this you'll have to login to your Facebook account when the application prompts. This will give you the access token that you would need to communicate. 
  • We'll be using the Facebook C# SDK ( You can get it from the mentioned link
  • Now we are ready to post our status:

var fb = new FacebookClient(this.AccessToken);
dynamic result = fb.Post("me/feed", new { message = "My second wall post using Facebook C# SDK" });

  • The complete project is attached with the article, All you have to do to make it work is to enter your App ID & App secret in the app.config.


Now let us move on to sending a tweet on Twitter. For this purpose we will be using a wrapper name Tweetsharp. It is widely regarded as the best in the business when it comes to integrating your application with twitter. Get the library from

To send a Tweet using your C# application,  first of all you will need to create an application by going to the following link:

  • Click on Create an app
  • After signing in with your twitter account credentials, you would be taken to a form where you need to fill in required information in order to create the application.
  • After you are done creating your application, you will be taken to your application's page. You need to take note of the keys highlighted in the following figure:

  • In case your Access token & Access Token Secret have not yet been generated, create them 1st. 
  • Now let us move on to the coding. Make a new Console Application.  
  • The App.config of your project should look something like this:

<?xml version="1.0" encoding="utf-8"?>
    <add key="ConsumerKey" value="<YOUR CONSUMER KEY GOES HERE>" />
    <add key="ConsumerSecret" value="<YOUR CONSUMER SECRET GOES HERE>" />
    <add key="AccessToken" value="<YOUR ACCESS TOKEN GOES HERE>" />
    <add key="AccessTokenSecret" value="<ACCESS TOKEN SECRET GOES HERE>" />
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <assemblyIdentity name="Newtonsoft.Json" 
            publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion="" />

  • Using the TweetSharp library, we'll simple send a tweet as follows:

TwitterStatus twitterStatus = twitterService.SendTweet(tweetMessage);


I would like to acknowledge the help that i took from the Facebook C# SDK Samples as well as the TweetSharp samples. I would love any input to this article to make it better. This is my first time, so dont be too hard on me Smile


This article, along with any associated source code and files, is licensed under A Public Domain dedication


About the Author

Umer Aziz Malik
Software Developer (Senior) Aurora Solutions (pvt) Ltd.
Pakistan Pakistan
When I was born, I was the 5,205,164,370th person alive on Earth & the 80,219,140,249th person to have lived since history began. Analogue at birth, digital by design. Leading the Trading Platforms teams at Aurora Solutions. A Manchester United aficionado. Always hungry. Extremely curious. Never idle. Usually found around my laptop, but when if you can’t find me check the football field or the cinema.

You may also be interested in...

Comments and Discussions

QuestionGetting error i.e. You are not logged in: You are not logged in. Please log in and try again. Pin
Bhushan SharmaG2-Mar-16 19:13
memberBhushan SharmaG2-Mar-16 19:13 
Questionupdates in 2015 ? Pin
kiquenet.com7-Aug-15 11:25
memberkiquenet.com7-Aug-15 11:25 
QuestionCan I avoid the log in screen Pin
shrishjain1-Jan-15 18:26
membershrishjain1-Jan-15 18:26 
QuestionToken Null Pin
Jose Murillo13-Nov-14 9:19
memberJose Murillo13-Nov-14 9:19 
AnswerRe: Token Null Pin
Member 101823867-Sep-15 16:14
memberMember 101823867-Sep-15 16:14 
GeneralRe: Token Null Pin
Member 1115459316-Sep-15 23:36
memberMember 1115459316-Sep-15 23:36 
QuestionError Pin
Member 1104240128-Aug-14 0:37
memberMember 1104240128-Aug-14 0:37 
AnswerRe: Error Pin
EveryNameIsTakenEvenThisOne10-Dec-14 8:13
memberEveryNameIsTakenEvenThisOne10-Dec-14 8:13 
QuestionAccess token is null Pin
Member 77988737-Jul-14 20:05
memberMember 77988737-Jul-14 20:05 
GeneralWhy i am getting null in url Pin
vivekvolt3-Mar-14 1:26
membervivekvolt3-Mar-14 1:26 
GeneralMy vote of 5 Pin
Manoj Gupta Jhansi10-Sep-13 22:42
memberManoj Gupta Jhansi10-Sep-13 22:42 
GeneralMy vote of 5 Pin
Anurag Gandhi24-Aug-13 8:24
memberAnurag Gandhi24-Aug-13 8:24 
QuestionLike a facebook status? Pin
LamboLambo3-Jun-13 23:42
memberLamboLambo3-Jun-13 23:42 
QuestionCan I post with multiple accounts on facebook? Pin
Agustín Martínez Martínez14-May-13 16:28
memberAgustín Martínez Martínez14-May-13 16:28 
Questionmmm Pin
Member 1004125411-May-13 11:50
memberMember 1004125411-May-13 11:50 
QuestionPost to Facebook Page Pin
Bhimani Hiral17-Apr-13 11:30
memberBhimani Hiral17-Apr-13 11:30 
Questionthank you Pin
Member 987064827-Feb-13 16:48
memberMember 987064827-Feb-13 16:48 
GeneralMy vote of 5 Pin
ppdeva19-Feb-13 22:53
memberppdeva19-Feb-13 22:53 
QuestionNice Post Pin
Manohar R Prabhu5-Feb-13 20:18
memberManohar R Prabhu5-Feb-13 20:18 
QuestionNice Post Pin
RaviSuhag4-Feb-13 21:50
memberRaviSuhag4-Feb-13 21:50 
Questionsmall change Pin
geodeath11-Jan-13 0:33
membergeodeath11-Jan-13 0:33 
AnswerRe: small change Pin
Niranjan Kumar Mahendralingam21-May-13 21:42
memberNiranjan Kumar Mahendralingam21-May-13 21:42 
QuestionNice Job Pin
Princess Dimaculangan5-Jan-13 15:58
memberPrincess Dimaculangan5-Jan-13 15:58 
Hello..Thanks for posting this great article of yours! Wink | ;) Keep on creating article about integrating to social networking sites. Can you also include Yammer? Smile | :) Big Grin | :-D
Questionauthentication Pin
audaijihad10-Dec-12 10:31
memberaudaijihad10-Dec-12 10:31 
QuestionHow can we build something like this using .Net 3.5 Pin
P Srikanth Gautham3-Dec-12 1:24
memberP Srikanth Gautham3-Dec-12 1:24 
GeneralMy vote of 4 Pin
Burak Tunçbilek20-Sep-12 7:22
memberBurak Tunçbilek20-Sep-12 7:22 
GeneralRe: My vote of 4 Pin
Umer Aziz Malik25-Sep-12 0:22
memberUmer Aziz Malik25-Sep-12 0:22 
QuestionThis is very urgent Pin
anusha saxena17-Sep-12 21:04
memberanusha saxena17-Sep-12 21:04 
AnswerRe: This is very urgent Pin
Umer Aziz Malik25-Sep-12 0:23
memberUmer Aziz Malik25-Sep-12 0:23 
GeneralDisplay newsfeeds on my website Pin
NaniCh3-Sep-12 22:27
memberNaniCh3-Sep-12 22:27 
QuestionFor C# application authorize Pin
vishal katoch14-Aug-12 10:16
membervishal katoch14-Aug-12 10:16 
AnswerRe: For C# application authorize Pin
Umer Aziz Malik15-Aug-12 1:31
memberUmer Aziz Malik15-Aug-12 1:31 
QuestionWhere are you using AppSecret? Pin
Alex_II26-Jul-12 14:08
memberAlex_II26-Jul-12 14:08 
AnswerRe: Where are you using AppSecret? Pin
Umer Aziz Malik29-Jul-12 23:35
memberUmer Aziz Malik29-Jul-12 23:35 
Questionhow can i login on our site using facebook username or id Pin
TusharMea22-Jul-12 21:52
memberTusharMea22-Jul-12 21:52 
QuestionWhat is OAUTH and How can i use this one in my ASP.NET website? Pin
Member 917112815-Jul-12 19:26
memberMember 917112815-Jul-12 19:26 
AnswerRe: What is OAUTH and How can i use this one in my ASP.NET website? Pin
Umer Aziz Malik15-Jul-12 21:36
memberUmer Aziz Malik15-Jul-12 21:36 
QuestionC# application Integration twitter API Pin
Yasodha.eng1-Jul-12 23:21
memberYasodha.eng1-Jul-12 23:21 
QuestionAdd an image Pin
Z@clarco28-May-12 3:38
memberZ@clarco28-May-12 3:38 
AnswerRe: Add an image Pin
Umer Aziz Malik28-May-12 3:57
memberUmer Aziz Malik28-May-12 3:57 
GeneralMy vote of 5 Pin
vquangchung16-May-12 4:39
membervquangchung16-May-12 4:39 
Questionfinding user's details after login Pin
abhishek.singh.valeteck15-May-12 3:15
memberabhishek.singh.valeteck15-May-12 3:15 
AnswerRe: finding user's details after login Pin
Umer Aziz Malik28-May-12 3:57
memberUmer Aziz Malik28-May-12 3:57 
GeneralVery good Pin
jesseseger10-May-12 2:17
memberjesseseger10-May-12 2:17 
GeneralRe: Very good Pin
Umer Aziz Malik10-May-12 2:20
memberUmer Aziz Malik10-May-12 2:20 
Question5 Pin
Kevin Marois9-May-12 8:19
memberKevin Marois9-May-12 8:19 
GeneralMy vote of 5 Pin
pmhsilva9-May-12 6:42
memberpmhsilva9-May-12 6:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 9 May 2012
Article Copyright 2012 by Umer Aziz Malik
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid