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

Advertisemen

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  :)


Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D