However supporting and publishing content on Facebook as a parallel channel to a normal website means increased work for many companies.
However posting on facebook doesn’t have to be a manual task that requires extra work. This post guides you to a solution that can easily be integrated in a existing CMS system, and enable cross posting of content to Facebook.
Facebook constantly changes their SDK and methods for communicating with Facebook. The script in this post supports the latest Facebook authentication changes that will be implemented i October 2012.
This post guides you through the creation of a PHP based Facebook application that can automatically post messages and other types of content on your Facebook wall.
The final result of the script is a timeline post like the example below
The process of building the post to Facebook PHP script requires the following steps:
- Download Facebook PHP SDK
- Register the Facebook application
- Build the Post to Facebook script
Download the Facebook SDKFirst step is to create a folder on your webserver for the Facebook application. In this example we’ll name the folder “facebook”
In the facebook folder create a subfolder names “facebook_sdk”
Download the Facebook PHP SDK from GitHub, unzip the files and upload the files to the “facebook_sdk” folder on your server.
The Facebook SDK files can be downloaded from here
Register the Facebook applicationFacebook only allows registrated applications to interact with Facebook accounts and pages. The next step is therefore to register your application (even if it hasn’t been built yet) .
You can register a new Facebook application on this page
To register your Facebook application you need first need to provide a unique app name.
- App ID/API Key
- App Secret
These informations are required for the application to be allowed to communicate with Facebook, but should also be kept as a secret.
Build the Post to Facebook scriptNow it’s time to build the actual PHP script for posting to the Facebook timeline.
The script assumes that you have downloaded and unzipped the Facebook PHP SDK (with it’s original file structure and content) in a subfolder named “facebook_sdk”.
The script is divided into three parts:
- Configuration where you insert your Facebook SDK information, and configeres which content to post on Facebook
- Facebook authentication and posting if a valid access token is avalilable
- Facebook authentication token download if no valid token is available (and then the script proceeds to step 2)
Next stepsThis post guided you through the initial Facebook application registration, and basic script for automatically posting content to a Facebook wall.
Next step could be to integrate this script in your CMS system, so a new post is automatically added to Facebook every time you’re updating the content on your site.
Facebook application authentication is changing from october 2012, which means that it’s no longer possible to generate permanent or offline access tokens. Unfortunately this means that it’s getting more complicated to post to Facebook from a application – especially if the Facebook application is running through a cron job or similar.