Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
I've been hacking at the FlatPress code for some time now and as one of the features I thought it was lacking was Facebook integration. I've experimented with adding Facebook posting features using the OAuth2 approach with the Facebook APIs but didn't particularly like those so I've decided to try the pre-authenticated tokens with the FacebookSession object and personally think it's a nicer solution.

This series of posts describe how a blog, such as FlatPress can be integrated with Facebook to have the ability to post to a Facebook page as well as your own user feed/wall. I will not go into details of how to modify internals of FlatPress to accommodate these features, that's beyond the scope of this article. I am also assuming that you have a Facebook page created already.

The PHP (version 4.0.0) Facebook SDK provides all the classes you would need to establish a session with Facebook and to manipulate the Graph APIs afterwards. This is what I used in the code I'll describe here.

Before going ahead with the code however, you will need to create a Facebook App. This is more or less a dummy App that is used for posting content on your behalf, it doesn't do much else and importantly does not need to go through the Facebook review process.

I am going to use my side-project blog, 300 George Street Blogumentary as an example in my screenshots.

First go to the Facebook Developers page and create an app. This is done through the My Apps, Add a New App menu.
fb01.png


For the platform select Website and then click Skip and Create App ID. You can select the Apps for Pages category if prompted.
fb02.png


Fill out the basic App information and in the Settings pane make sure to fill in the Site URL as Facebook checks the originating source of your requests to make sure it matches this URL.



Take a note of the App ID and App Secret as these are needed for the code to work. These should be stored on the server side somewhere, not hard-coded. They are needed to establish a Facebook session.
fb03.png


You can make the App public now (or wait until you finished writing the code). If the App is not public, any posts it makes will not be visible to anyone else but yourself. To make the App public, head over to the [i]Status & Review tab and flick the switch, then click Confirm.
fb04.png


Now that the app is set up, head over to your Facebook page that the App will represent and click the About, Page Info link. Scroll all the way down and take note of the Facebook Page ID.
fb05.png
fb06.png



Now all that is left is to get the pre-authenticated token from the Graph API Explorer
page. From the Application drop-down, select the App you have just created.
fb07.png


Click Get Access Token and make sure to select the manage_pages and publish_actions on the Extended Permissions tab. After you click Get Access Token a new token will be generated that you can copy/paste, take note of this token.

With all the info assembled you can now get to the code, however that will have to wait until the next post which will be put up soon (in a day or two).

Update: The second part of this series is now available, go check it out to see the PHP code for posting to Facebook.

-i

Skip down to comments...
Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
 
comments powered by Disqus
Other posts you may like...