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).
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:
- This sample is target on windowsphone 7.1 os
- Before going to post message on fan page,you must login in facebook with access_token by creating Facebook Application on Facebook developer site. Here is the procedure to login with facebook http://code.msdn.microsoft.com/wpapps/Latest-Direct-Facebook-519df38b (or) integrate_Facebook_to_Your_Windows_Phone_Application
- So that this post assumes you are succeeded with FaceBook login.
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<string, object>)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<string, object>)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<string, object>();
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:
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<string, object>)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<string, object>)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<string, object>(); 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:
Source file at:FacebookFanPagePostSample
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 @Subramanyam_B
Have a nice day by Subramanyam Raju :)
Source file at:FacebookFanPagePostSample
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 @Subramanyam_B
Have a nice day by Subramanyam Raju :)
thanks for sharing this informative post i really like it.
ReplyDeleteiphone
I'm not familiar with C#, just only know VB.Net but I'll try your method to see how it works.
ReplyDeleteThanks alot
The Ultimate FB Content Pro Review
Nice article.
ReplyDeleteHow to fetch user friendlist from facebook?
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
ReplyDeleteI 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!
ReplyDeletePlease 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
ReplyDeleteI 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!
ReplyDeleteReply facebook
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
ReplyDeleteThanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing...
ReplyDeletefacebook