Simple 5 Steps to publish on a facebook wall using DotNet C#/ cSharp

March 7, 2010 · 37 Comments
Filed under: .Net, ASP.NET, ASP.NET 2.0, C#, FaceBook Integration, Featured, VB.Net 

There are many Libraries available for C# and Dotnet to publish on facebook.

According to facebook Wiki posting on a wall is very confusing and very difficult to write a program to publish on a wall.

I spent around 2 weeks reading many articles and many documents, Wiki on facebook but in vein and tried many ways and finally I got one workable model. Below are 5 simple steps to publish on a Facebook wall.

Step1: Login to Facebook

First login to Facebook and goto the url http://www.facebook.com/developers/ then

Click on “+ Set Up New Application” button to start creating the application as shown below.

start application

Provide the application name, click agree for facebook terms and click on “Create Application” button.

Fill in application Name

create app step1

Now Application is created for you. Just copy the Application API Key, Application Secret and Application ID details which will be used to write the application code.

application page

Now goto Canvas link and enter any url.

canvaspage

Next goto Connect URL link and enter the same url.

connecturl

Then click on Save. That’s it we have created a facebook application with an Iframe.

Now Copy Application API Key, Application Secret and Application ID details which will be used to write the application code.

Now download any of the available libraries on facebook http://wiki.developers.facebook.com/index.php/User:ASP.NET

(OR)

Microsoft SDK for Facebook Platform, which supports Facebook Connect, FBML and IFrame canvas page applications, and ASP.NET MVC. For issues and discussions about the SDK see the project on Codeplex.

Step2: Generate One Time Session key

How to generate One Time Session key:

Run below URL to get temporary token for the selected user by logging into Facebook.

https://login.facebook.com/code_gen.php?api_key=API_KEY&v=1.0

Note: Please replace “API_KEY” with your application API key from above page.

Then we will get a temporary token key.

allowaccess

generatemylogin info

savemyinfo

This is one time token key that we can use to generate a permanent session key. Careful! Don’t try to execute this programs many times

Step3: Generate one time session key




Below is the sample code to generate one time session key.

For example, the full URL for logging in a user could be:

http://www.facebook.com/login.php?api_key=YOURAPIKEY&connect_display=popup&v=1.0&next=http://www.facebook.com/connect/login_success.html&cancel_url=http://www.facebook.com/connect/login_failure.html&fbconnect=true&return_session=true&session_key_only=true&req_perms=read_stream,publish_stream,offline_access

If the user is redirected to the URL specified by the next parameter, then Facebook grants your application a session. This session is appended to the URL as a JSON-decodable object of the form:

&session={“session_key”:”SESSIONKEY”, “uid”:USERID, “expires”:0 || UNIXTIME, “secret”:”SESSIONSECRET”}

In continuing with the above example, the redirect for a successful login would be:

http://www.facebook.com/connect/login_success.html?session=%7B%22session_key%22%3A%223.kxhAu6W0qo_bLGjmdWrgfw__.86400.1243443600-688626964%22%2C%22uid%22%3A%22688626964%22%2C%22expires%22%3A1243443600%2C%22secret%22%3A%220NVNMxpO6jVyDcVCvVv_PA__%22%2C%22sig%22%3A%22ac1c0c77c137567389defea70481b7aa%22%7D

If the user grants your application the offline_access extended permission, 0 gets returned for expires and the session never expires unless the user removes the application. In this case, you should store the session key so the user doesn’t have to log in the next time he or she launches your application.

Once the browser has been redirected successfully and you have your session information, you should automatically close the browser window.
Note: The above code will execute only once. We should note down the above session key, This will be used to auto login into the application.

If you don’t save these session key values you should generate other token key to create one time session key.


Step4:

Giving Permission to your application to publish on facebook wall. To give permission just replace the your API key in below URL and execute in browser.

http://www.facebook.com/login.php?api_key=APIKEYXxxxxxxxxxxxxxxxxx&connect_display=popup&v=1.0&next=http://www.facebook.com/connect/login_success.html&cancel_url=http://www.facebook.com/connect/login_failure.html&fbconnect=true&return_session=true&req_perms=read_stream,publish_stream,offline_access

Then you must see the below 3 Screens

If you don’t see the below then your call back URL or Canvas URL must be incorrect, please check again your application settings and execute the URL again.

allowpermission

allowpublishing

Then on final page, you will see a success message. That’s it you have given permission for read_stream,publish_stream and offline_access.

Step5: Publishing the message with Image and link on Facebook Wall using cSharp/ C#

Publishing a Post With Image and Action Link in C# using facebook developer toolkit v2

C# Code to create facebook object with onetime session key and publishing the message on Facebook Wall.

public void Post(facebook.API fbAPI, string appLink)
{
 string response = fbAPI.stream.publish( "publish steven on facebook.",
new attachment() {
name = "I am a good guy !", href = appLink, caption = "{*actor*} Steven Publish on facebook wall",
description = "Helping other people, I became a new good guy.", properties = null,
 media = new List<attachment_media>() { new attachment_media_image()
{ src = "http://blog.theunical.com/wp-content/uploads/2009/11/start-application.jpg", href = appLink } } },
new List<action_link>() { new action_link() { text = "Become a good guy",
 href = appLink } }, null, 0);
}

Now you will see the post on wall Great.

published on facebook

So thrilling isn’t we can also publish photos videos on wall.

http://wiki.developers.facebook.com/index.php/Stream.publish

have a great day

— Steven

Please don’t copy this content to any site. This is fully protected by TheUnical Technologies

Multi-tenancy in ASP.NET MVC – Breaking it down

February 6, 2010 · Leave a Comment
Filed under: ASP, ASP.NET, ASP.NET 2.0 

In the last entry, we covered the basics of what I consider multi-tenancy to be, and why we might perhaps want to write our ASP.NET MVC web application with

Download details: ASP.NET MVC 2 RC 2

February 6, 2010 · Leave a Comment
Filed under: ASP, ASP.NET, ASP.NET 2.0 

ASP.NET MVC 2 RC 2 provides a new Model-View-Controller (MVC) framework on top of the existing ASP.NET 3.5 SP1 runtime.

Professional ASP.NET 2.0 XML | ebooks library

February 6, 2010 · Leave a Comment
Filed under: ASP, ASP.NET, ASP.NET 2.0 

Publisher: Wrox Language: English ISBN: 0764596772 Paperback: 566 pages Data: January 18, 2006 Format: PDF Description: * The foundation for most Web.


ebooks library – http://www.ebookslib.org/

THINGS TO DOWNLOAD: Pro ASP.NET 3.5 in C# 2008 -=[BonVD]=-

February 6, 2010 · Leave a Comment
Filed under: ASP, ASP.NET, ASP.NET 2.0 

As you no doubt already know, ASP.NET is Microsoft's next-generation technology for creating server-side web applications. It's built on the Microsoft .NET Framework, which is a cluster of closely


THINGS TO DOWNLOAD – http://vikramdhananja.blogspot.com/

Create object in Asp.netASP.NET

February 6, 2010 · Leave a Comment
Filed under: ASP, ASP.NET, ASP.NET 2.0 

Create object in Asp.net ASP.NET. 7 Hours Ago. hi all, Is this is there any way in asp.net to create object of a web form in any other web form to access its member function ?? Quick reply to this message


DaniWeb IT Discussion Community – http://www.daniweb.com/news/writer311962.html

ASP.NET MVC 2 RC2 Released

February 6, 2010 · Leave a Comment
Filed under: ASP, ASP.NET, ASP.NET 2.0 

After the positive feedback from ASP.NET MVC 2 RC1, Microsoft has decided to release RC2 (Release Candidate 2). This release fixes a few bugs in the RC, but adds one big feature, and that's a change to the validation model.


DevCurry – http://www.devcurry.com/

Skitsanos for RIA: Predictive Fetch with jQuery and the ASP.NET

February 6, 2010 · Leave a Comment
Filed under: ASP, ASP.NET, ASP.NET 2.0 

In the ASP.NET Ajax Library, the mechanics of master-detail views are largely defined in the logic of the DataView component and in the way the component handles and exposes its events. This month I'll go one step further and discuss


Skitsanos for RIA – http://blog.skitsanos.com/

Well, we're still blogging, anyway

February 6, 2010 · Leave a Comment
Filed under: ASP, ASP.NET, ASP.NET 2.0 

We're Microsoft fans here at LiveSide, and we try to use Microsoft products whenever we can, which is why we're on Community Server (an ASP.net solution),

See all stories on this topic

ASPNET Release ASPNET MVC 2 RC 2

February 6, 2010 · Leave a Comment
Filed under: ASP, ASP.NET, ASP.NET 2.0 

Microsoft Source License for ASPNET PreRelease Components This license governs use of the accompanying software If you use the software you accept this

Next Page »