Post files in FaceBook wall using Graph API

Steps to Post files in FaceBook wall using Graph API is given below.

1)Create a Facebook application to get an AppID and Secret key for your Website or Blog. Use the following link to open Facebook developers App site.

https://developers.facebook.com/apps

 

2)Add App ID,secret key in code and also make reference to DLL for Facebook integration.

Download DLL for FaceBook Integration here

Aspx Code

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <h2>Upload or post photos, images, or pictures to FaceBook wall with comments using Graph API in ASP.Net website</h2>
            <asp:FileUpload ID="FileUpload_Demo" runat="server" />
            <br />
            <br />
            <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine"></asp:TextBox>
            <hr />
            <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="UploadPhoto" />
        </div>
    </form>
</body>
</html>

 

C# Code

protected void Page_Load(object sender, EventArgs e)
       {
           string API_Key = ConfigurationManager.AppSettings["API_Key"];
           string API_Secret = ConfigurationManager.AppSettings["API_Secret"];
           FaceBookConnect.API_Key = API_Key;
           FaceBookConnect.API_Secret = API_Secret;
           if (!IsPostBack)
           {
               string code = Request.QueryString["code"];
               if (!string.IsNullOrEmpty(code))
               {
                   FaceBookConnect.PostFile(code, "me/photos", (HttpPostedFile)Session["File"], Session["Message"].ToString());
                   Session["File"] = null;
                   Session["Message"] = null;
               }
           }
       }

       protected void UploadPhoto(object sender, EventArgs e)
       {
           Session["File"] = FileUpload_Demo.PostedFile;
           Session["Message"] = txtMessage.Text;
           FaceBookConnect.Authorize("user_photos,publish_actions", Request.Url.AbsoluteUri.Split('?')[0]);
       }

 

Output

The below demo shows how the post/image gets posted in facebook on Upload button click.

 

Image posted in FaceBook Wall on Upload button click

Post files in FaceBook wall using Graph API

 

 

 

 

Demo Code

Download