Google WindowsPhone Facebook Integration:How to post message/image to FaceBook Fan Page(C#-XAML) | SubramanyamRaju Xamarin & Windows App Dev Tutorials

Wednesday, 28 May 2014

WindowsPhone Facebook Integration:How to post message/image to FaceBook Fan Page(C#-XAML)

Introduction:


Now its time to a requirement is "How to post message/image to Facebook Fan Page from windows phone".Actually there is lot of resources is available for posting message on facebook profile wall page.But for posting message on facebook fan page,there is no resources available.However we will talk with this post.

Lets understand requirement 

1)What is a fan page on Facebook:
A fan page is the only way for entities like businesses, organizations, celebrities, and political figures to represent themselves on Facebook.
Unlike a personal Facebook profile, fan pages are visible to everybody on the Internet. Anyone on Facebook can connect to and receive updates from a page by becoming a fan (i.e. ‘Liking’ the page).
If you interesting on knowing more about fan page visit this link

Building the Sample:

Description:

After successfully Facebook Connect with access_token ,Once you got it, you could do anything with the API. For now, I will show you how to post to the FaceBook Fan Page with specific message/image. So lets start with few steps

1)Extended Permissions for Posting message on facebook Fan Page:

Yes we need to some following extra permissions to post message on Facebook page. 

C#
 private const string ExtendedPermissions = "user_about_me,read_stream,publish_stream,manage_pages";

2)How to post message/image on facebook Fan Page:

It is very simple and similar to posting message on facebook profile page.But we need to have some changes .
To post message on facebook profile page:
C#
var fb = new FacebookClient(_accessToken); 
fb.PostAsync("me/feed", parameters);

To post message on facebook fan page ,we just need to replace "me/feed" to "FacebookFanPageName/feed".
 for example
C#
var fb = new FacebookClient(_accessToken); 
fb.PostAsync("SubramanyamRajuWindowsPhone/feed", parameters);

Here i tried to post message on my facebook fan page name is: https://www.facebook.com/SubramanyamRajuWindowsPhone

By the way the total code to post message/image on fan page is:
C#
 private void PostToFaceBookFanPage_Click(object sender, RoutedEventArgs d) 
        { 
            var fb = new FacebookClient(_accessToken); 
 
            fb.GetCompleted += (o, e) => 
            { 
                if (e.Error != null) 
                { 
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message)); 
                    return; 
                } 
 
                var result = (IDictionary<stringobject>)e.GetResultData(); 
                var id = (string)result["id"]; 
                result["id"] = id; 
 
 
                fb.PostCompleted += (oo, args) => 
                { 
                    if (args.Error != null) 
                    { 
                        Dispatcher.BeginInvoke(() => MessageBox.Show(args.Error.Message)); 
 
                        return; 
                    } 
 
                    var result1 = (IDictionary<stringobject>)args.GetResultData(); 
                    _lastMessageId = (string)result["id"]; 
 
                    Dispatcher.BeginInvoke(() => 
                    { 
                        NavigationService.GoBack(); 
                        MessageBox.Show("Message Posted successfully"); 
 
 
                    }); 
                }; 
                var fbupload = new FacebookMediaObject 
                { 
                    FileName = "images.jpg", 
                    ContentType = "image/jpeg" 
                }; 
                fbupload.SetValue(data); 
                var parameters = new Dictionary<stringobject>(); 
                parameters["message"] = "SubramanyamRaju WindowsPhone Tutorials \n www.bsubramanyamraju.blogspot.com"; 
                // parameters["name"] = "My FB Pic"; 
                parameters["picture"] = "http://azujenergia.hu/files/2013/04/blossoming-flower4.jpg";//to post image on facebook 
               // parameters["link"] = "http://www.logictreeit.com"; 
                fb.PostAsync("SubramanyamRajuWindowsPhone/feed", parameters);//to post message pn facebook fanpage profile 
               // fb.PostAsync("me/feed", parameters);//to post message on user profile 
 
            }; 
 
            fb.GetAsync("me?fields=id"); 
        }

 3)Fan Page ScreenShots:


Note: Please share your thoughts,what you think about this post,Is this post really helpful for you?otherwise it would be very happy ,if you have any thoughts for to implement this requirement in any another way?I always welcome if you drop comments on this post and it would be impressive.

Follow me always at  
Have a nice day by  :)


9 comments:

  1. thanks for sharing this informative post i really like it.
    iphone

    ReplyDelete
  2. I'm not familiar with C#, just only know VB.Net but I'll try your method to see how it works.
    Thanks alot
    The Ultimate FB Content Pro Review

    ReplyDelete
  3. Nice article.
    How to fetch user friendlist from facebook?

    ReplyDelete
  4. Hi, i'm dev with wp8.1 and i want to publish image control to fb, but i don't know convert image control to byte[], you can help me? Ste

    ReplyDelete
  5. I don't "Post On Wall". This is error: "(OAuthException - #200) (#200) The user hasn't authorized the application to perform this action" please help me. Thanks!

    ReplyDelete
  6. Please share your thoughts,what you think about this post,Is this post really helpful for you?otherwise it would be very happy ,if you have any thoughts for to implement this requirement in any another way?I always welcome if you drop comments on this post and it would be impressive.facebook

    ReplyDelete
  7. I don't "Post On Wall". This is error: "(OAuthException - #200) (#200) The user hasn't authorized the application to perform this action" please help me. Thanks!
    Reply facebook

    ReplyDelete
  8. I don't "Post On Wall". This is error: "(OAuthException - #200) (#200) The user hasn't authorized the application to perform this action" please help me. Thanks!facebook

    ReplyDelete
  9. Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing...
    facebook

    ReplyDelete

Search Engine Submission - AddMe