WordPress and Facebook – Part 4
Back in August I wrote about the Wordbook plugin for WordPress which basically replicates posts from your own hosted WordPress (or WordPress MU) blog into your Facebook account where they appeared on your wall.
The plugin did something well but it lacked several things that I’d like it to do. So I started adding them. The sidebar widget was the easiest thing to do as that was pretty much self contained and as you can see from this blog its working quite well.
The plugin had a very annoying habit of re-posting a post if you edited after more than a few days and it seemed to publish posts to Facebook when you’d least expect it.
So I rehashed that code and got it all working.
But everything was hard coded. What if I wanted to force it to republish a post to Facebook when I edited it, what if I wanted to automatically republish if editing after 10 days, except that I didn’t want it to do it for a specific post.
That was all the easy stuff.
But what about comments? Wouldn’t it be cool if comments posted on your Facebook copy of the post could be pulled down into your blog as comments to that post. Sure it would be cool, and it wouldn’t be that difficult would it.
WRONG!
The plugin used the Feed.publishUserAction API call. Its a neat little function but it doesn’t return the Post ID for the post you just made into facebook, and you need the Post ID to pull comments back. The obvious answer was to use the stream.publish API call instead. That returns the Post ID and then you can simply get the comments by using Stream.getComments and passing it the post ID in question. To get all of that working I needed to grab the latest version of the API files and I had to recode the way the plugin posts as Stream.Publish uses a different structure for a post.
So once all that was working and I’d coded up a nice options page and put an option block on the Edit/Add Posts page so you can override some defaults (like saying you DON’T want to import comments for a post) all that was left was to code up a comment fetching job and work with WP-CRON to schedule it.
I finished all of that a couple of weeks ago, and I’ve been debugging it since but now I think its probably ready to escape into the wild and if anyone is mad enough to want to test it then Here it is
Some quick notes on Upgrading from the existing Wordbook plugin.
- You need to de-activate the old plug in first.
- Then DELETE the wordbook folder from wp-content/plugins and then upload the new version. DONT just copy the new files up.
- Re-activate the plugin
- Go to the Options page for the plugin and you can set all the new wizzy options. If you want to pull comments from your Facebook account you’ll need to grant the plugin permission to read from your stream. If you don’t grant this permission then you can’t pull comments, and I’ve no idea what my code will do if it tries to do that because I didn’t test it! So you have been warned!
Debugging.
The only place I’ve put any real debugging in is in the cron job code because its very hard to actually work out if its working if there are no comments to pull. Debugging for that can be enabled by editing two lines in wordbook_cron.php:
define (‘DEBUG’, false); which you change to true
and
$debug_file=’/tmp/wordbook_’.$table_prefix.’debug’; which you may need to change if you want to change the output directory.
Caveats
You knew there would be some didn’t you!
I developed this on WordPress MU which is the MultiUser version of WordPress. I developed it using 2.8.4a which is the same as 2.8.4 in standard WordPress. I HAVE NOT tested it on older versions so I cannot guarantee things like the draggable box on the Edit/Add Page will work if you are not on V2.8.4
As I’ve now sort of released this plugin I’ve created a page where I’ll log any changes to it in future. So if you want to keep upto date then you’ll need to check my Wordbook Page
October 28th, 2009 at 4:34 pm
Well will you look at that, I managed to miss one of the unicode conversions!
October 28th, 2009 at 5:25 pm
Hi Stephen ,
I am downloading and will do a fresh install. I will let you know what the result is after
Alex Duvot ( from FB)
October 28th, 2009 at 9:28 pm
Wordbook failed to communicate with Facebook for testing wordpress to facebook 2: method = stream.publish, error_code = 200 (Permissions error). Your blog is OK, but Facebook didn’t get the update.
October 28th, 2009 at 9:30 pm
Thats’ a FB API error (200) which indicates insufficient permissions, not a lot I can do about that unfortunately unless its generic and caused by a change in the permissions needed to post
But I’ve seen Facebook throwing account errors this evening
If you go to your Facebook Application Settings and select to show “Granted additional permissions” you should see Wordbook in all the categories including Publish to streams and Access streams.
October 29th, 2009 at 1:31 am
thanks for the fix
resolved
This is the best plugin I have seen or used so far.
October 29th, 2009 at 8:13 am
Alex, glad the fix worked. I’ll add it into the upgrade notes later today.
November 8th, 2009 at 6:23 pm
Hi Steve,
Tried to download it but the zip file is invalid?? Won’t let me open it up and if it does, it extracts a 0kb doc.
Thanks.
November 8th, 2009 at 6:47 pm
How very odd, I’ll look into it. However the static page for it works:
http://blogs.canalplan.org.uk/steve/wordbook/
November 8th, 2009 at 7:21 pm
Hi Steve, now it downloads a file ~250kb in size but when I open it up in WinRar it gives me an error and says “unexpected end of compilation”!
Thanks!
November 8th, 2009 at 7:26 pm
Can you use winzip or anything else? I’m in the middle of things on my Linux Laptop (actually working on more enhancements to the plugin) so I can’t check if its OK from Vista.
November 8th, 2009 at 7:30 pm
Tried another program and still coming up as invalid!
November 8th, 2009 at 7:52 pm
I’ve just booted up into Vista and Windows unpacked it fine. I also downloaded and installed the demo of Winrar and it opened it fine as well.
November 8th, 2009 at 11:40 pm
Sorry still getting errors in both WinRar and opening with Windows.
November 9th, 2009 at 8:30 am
Thats very odd. Have you tried clearing out any copies you’ve downloaded and deleting your internet cache?
Also I assume you’re saving the file to your computer rather than trying to unzip it on the fly?
November 24th, 2009 at 5:02 am
Hi: Thanks for your hard work! I installed this plugin and immediately got a notice that a new version of the plugin (0.14.10) is available.Have the same fixes been integrated to 0.14.10? Or are these options only in 0.14.08?
Thanks again,
Mary
November 24th, 2009 at 2:41 pm
My forked version isn’t in the WP extensions repository. I’ve rolled up the latest changes in the “core” version into my forked version. So if you’ve installed my fork then you need to ignore the version notification on the plugin page and use the check on the plugin options page instead.