Posts Tagged ‘facebook’

Facebook C# SDK how to post on wall

Written by Alex on . Posted in Uncategorized

We used Facebook C# SDK for one of our clients to post messages on Facebook wall.
The API is easy to use and understand, and in this article we are going to describe all steps to post on Facebook wall using Facebook API.

Facebook provides Graph API for all features, including posting on the wall. The name of the method is “feed”:

https://graph.facebook.com/[ID_OF_WALL_PAGE]/feed

You have to send HTTP post message to the url above with the post object. The post object has the following properties:

  • picture
  • link
  • message
  • name
  • caption
  • description
  • category

and it looks like this in browser

facebook-post-structure

Posting on Facebook wall with C# Facebook SDK

This example uses .NET 4, but C# Facebook SDK also support .NET 3.5.
dynamic messagePost = new ExpandoObject();
messagePost.picture = "http://yaplex.com/uploads/yaplex-logo-with-text-small.png";
messagePost.link = "http://yaplex.com/";
messagePost.name = "[name] Facebook name...";

// "{*actor*} " + "posted news..."; //<---{*actor*} is the user (i.e.: Alex)
messagePost.caption = " Facebook caption";
messagePost.description =
    "[description] Facebook description...";
messagePost.message = "[message] Facebook message...";

string acccessToken =
    "xxxx5120330xxxx|4xxxxx0c0f95bd3f62dxxxxx.1-10000xx4x73xxxx|2xx5xxx0566xxxx|z2xxxx37dxxxxsdDS23s_Sah34a";
FacebookClient appp = new FacebookClient(acccessToken);
try
{
    var postId = appp.Post("24351740xxxxxx" + "/feed", messagePost);
}
catch (FacebookOAuthException ex)
{
    //handle oauth exception
}
catch (FacebookApiException ex)
{
    //handle facebook exception
}

The code is pretty easy, and the most important thing you need is Facebook Access Token.

Once you have access token, you create facebook wall message and submit it to facebook graph API url with HTTP POST request.

I used C# SDK which was available on codeplex, but now project moved to there own website at csharpsdk.org

Facebook multi friend selector dialog width is incorrect

Written by Alex on . Posted in Uncategorized

In my Facebook application I had an invite friends dialog. The dialog was pretty simple and requires a couple of lines coding. But I faced a big problem when created this dialog. My multi friend selector dialog appeared at the right side of window and half of the dialog was not visible.

facebook-multi-friend-selector-invalid-width

I tried to fix it with CSS but it was no luck. When rendering this dialog used iframes and it was not so easy to access code inside of iframes and modify some CSS styles. But two days of looking for solution gave me some results. I found than fb:serverfbml tag has attribute width which was incorrect by default. And changing this attribute helped me to set correct width for invite friends dialog.

Note: width property for invite friends dialog

This width attribute is not CSS attribute but the property of serverfbml tag, that’s why I spend so may hours working on this issue.

Facebook multiselect dialog box: source code

<div id="dialogInviteFriends" style="overflow: hidden; ">
        <fb:serverfbml  width="500px" >
            <script type="text/fbml">
            <fb:fbml>

                <fb:request-form
                        type="your app"
                        content='<fb:req-choice url="http://apps.facebook.com/abc/"
                        label="Accept"/>'
                        invite="true"
                        action="http://apps.facebook.com/abc/"
                        method="POST"
                        target="_top"
                        >

                    <fb:multi-friend-selector
                            actiontext="abc to friends"
                            showborder="true"
                            rows="3"
                            cols="5"
                            email_invite="true"
                            import_external_friends="true"
                            />

                </fb:request-form>
            </fb:fbml>
            </script>
        </fb:serverfbml>
    </div>