Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > sumbit to facebook View modes: 
User avatar
Member
Member
lwhittemore-emh - 5/10/2012 12:26:30 PM
   
sumbit to facebook
Has anyone done any work in kentico with facebook? We had a client ask today if there was a way that he could submit pages to facebook via kentico. They would like it to be a one stop shop to update their site and then have it post to facebook.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 5/14/2012 4:14:48 AM
   
RE:sumbit to facebook
Hi,

do you mean that they would like to update facebook profile page? Write some update to the wall?

In this case please take a look at this tutorial:
Integration with Facebook

Best regards,
Ivana Tomanickova

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 5/15/2012 2:10:38 PM
   
RE:sumbit to facebook
I have done some work with this.

I have made it so that editors can click a link that is visible only to them to post a page as a link on a Facebook fan page wall that they administer. I made it so it can be automated, but that requires quite a bit of code and a pain in the butt when Facebook removed their "access my data any time" permission on May 1st.

My Recommendation:

Use the Facebook javascript api to create a few methods to allow you to authenticate, get permission, and use the auth_token to post a page to a fan page. Here are the steps that you need to follow.

1. Create a facebook app on facebook. You will need the app id and possibly the app secret to do what you need. Make sure you set it up as a web application and configure the domain of the site you are placing it on.

2. Go here http://www.sergiy.ca/post-on-facebook-app-wall-and-fan-page-wall-as-admin/ to read up on how to use the javascript api to post to a wall. It is a bit outdated, but it still works. Take note that you need to change 'perms' to 'scope' when requesting the access token. If the user who is logged in is not an admin of the fan page you want to post to, it won't work unless you use a stored and valid access token generated from someone who is an admin. Those tokens only last about 2 hours though, unless you follow facebook's process for requesting an extended access token, which last 60 days (this process can be a pain).

When you get your response back from the request, you will need to iterate through the pages until you find the one with the page id that you want to post to. Get the access_token from that page entry and use that to make your post to the wall.

3. Facebook auto scrapes a page to get the image and description it will automatically use the page title and meta description for the title and text of the post, but it will use the first image it finds as the image unless you specify otherwise using a link tag. Make sure that the description meta is filled out or a macro is used to grab it from a property of your document in kentico or else it will only post a title and image to facebook. You can either use the open graph (og) meta tags or a <link rel="image_src" href="absolutelinktoyourimage"/> tag to set the image for the post.

I will see if I can't make a nice webpart that does all of this today and I'll let you know if I get it done.

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 5/15/2012 2:54:59 PM
   
RE:sumbit to facebook
After you get your facebook app and have added the javascript facebook api initialization code to your page (you should put it in your master template) you can use this javascript to post a link to the current page to a fan page with the specified id


postCurrentUrlToFanPage(<YOUR FAN PAGE ID>);

function postCurrentUrlToFanPage(fanpageID){
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
var wallPost = {
access_token: accessToken,
link: window.location.toString()
};
FB.api('/'+fanpageID+'/links', 'post', wallPost, function(response) {
if (!response || response.error) {
alert('Error occurred');
} else {
alert('Success!');
}
});
} else {
if(confirm('You were not logged in to Facebook or you need to (re)authorize. Would you like to do so now?') == true)
{
FB.login(function(){
postCurrentUrlToFanPage(fanpageID);
},{scope:'publish_stream,manage_pages'});
}
}
});
}