How To: Sync Facebook Status With Twitter
Computers, Facebook, How To's, Internet, Software Add commentsUpdate: Please read the Notice at the bottom of the post.
I am addicted to using Twitter. TwitterBerry makes it very easy to update my status from my mobile phone which can then be placed on my blog via Twitter Tools. Most of my friends however don’t even know what Twitter is and are always using Facebook. This article will explain how you can use your Wordpress blog to one-way sync your Facebook status with Twitter.
Before we get going, there are a few requirements for this to work. You will need to have Wordpress installed and be able to add plugins. I will be using Twitter Tools and adding some code to make this work. In terms of updating Facebook’s status, we will be using the curl command in PHP over Facebook’s mobile service. All credit for connecting to Facebook goes to Christian Flickinger.
Instructions
First you will need to download and install Twitter Tools. Once installed and working, we will need to add a few lines of code to the source file. Open twitter-tools.php in your favorite editor and add the following.
First you need to tell the plugin to call a function every time you update Twitter. To do this just add an add_action call anywhere in the file. Below is the code you need to add, where update_facebook is the function you are calling.
This tells the plugin to call the update_facebook function when you add a new tweet.
Next you need to create the function update_facebook to update Facebook. This function is a little lengthy to place in the article so you can get it from the complete code. It basically uses the method Christian created.
Get The Code
You can download the complete code here. All you need to do is paste this block of code into the twitter-tools.php file, anywhere is fine, and don’t forget to add your Facebook credentials to the update_facebook function. That’s it. Let me know if you are having problems.
Notice
It has recently come to my attention that creating automated scripts that interact with Facebook is a violation of the Terms of Service agreement. Facebook contacted me and advised me to please remove my code, which I have graciously done. I am not exactly sure of the limitations since 8hands does it as mentioned below in the comments. I will keep you updated of future progression. If you have downloaded the code, you should stop using it or risk losing your Facebook account.
8hands, the profile aggregator, have been doing it forever! (or at least a month since i have it.)
and it has so many other great features..
Why going on a website when I can update my tag line/mood via my desktop? and to install Wordpress for it? I don’t get it.
@Pete: Thanks for the tip. I had never heard of 8hands before but it still doesn’t help me. First of all I use a Mac and secondly, I like to update my status via my Blackberry. I also already have a blog with Wordpress installed so it is a easy way to sync the status without giving some third party my username and password to Twitter and Facebook.
Thanks for the TwitterBerry plug! Please let me know if you have any feature requests or feedback. Cheers!
Jason of orangatame dot com
Ahh, great use of the Fmobile/status hack! I’m glad to see so many people are finding the code useful. Thanks for the credit as well!
Thanks for pointing my attention towards this, Blake. I will be looking at the Drupal equivalent
I use Twitterberry on my blackberry as well. I’m not sure how me updating my twitter from it will tell my wordpress blog to kick off twittertools to then run your code. Can you explain this to me?
@Jason: The process works as follows: TwitterTools works by checking every few minutes (this is configurable in the code) your tweets to see if they have been updated. If there are new tweets, among doing other things, TwitterTools will call the function I wrote to also update your Facebook status, with your latest tweet. If your status has not been updated, TwitterTools will not call the function I wrote (this keeps Facebook from repeating the same status message).
Fantastic idea Blake, thank you! I’m still fiddling with it to get it working. Do I assume correctly that the section marked
// Twitter User Configurable Settings
is actually for the Facebook settings?
@Daniel: Thanks for the catch. Yes, that is your Facebook credentials. I fixed the code.
Hi. I am very intregued by this tweak, but I’m having some trouble getting it working. I deactivated Twitter Tools (after some threatening words from WordPress about modifying active plugins), pasted the code block you provide into the bottom of twitter-tools.php, and reactivated the plugin. I then tried a sample tweet. It appeared on my Twitter Tools column as expected, but doesbn’t seem to have updated my Facebook profile.
Am I doing something wrong?
@John T Davis: Sounds like you are doing it right. Did you remember to add your Facebook credentials to the file? Are you getting any text for your Facebook status or nothing? Another thought is to add the Facebook mobile app. Not sure if this is required or not. I have it added but never set it up with my mobile number. Let me know if you still can’t figure it out.
For what it’s worth, I’ve had similar problems. I haven’t investigated fully yet, but I did coax Christian’s original code into updating my Facebook status. Hooking it all together as per this article though — while I can see it should work, the updates only get as far as Twitter and WP; never into FB. I’ll keep trying and see what else I can find.
I’m no PHP wizard, but what I have worked out is that the curl_exec calls are returning 1 (the result) rather than the page text, despite CURLOPT_RETURNTRANSFER being set to 1. Odd, and I don’t understand why it doesn’t do that when that routine is isolated, nor when others are using it.
Try pulling the code for the update_facebook() function out to its own php file. You will need to remove all lines in the code up till the $status = line. Then just set status to some string. Here is an example of what you need. If you can get this to work then you have isolated the facebook function. That will mean that there is a problem with Twitter Tools calling the function.
Got it working after some fiddling with the my_cookies references and taking out the FOLLOWLOCATION flag (which doesn’t appear to be needed). Obviously others have it working without these problems, so it may be an issue with my web ISP.
I’ve written it up here: http://www.geekrant.org/2007/08/29/twitter-to-wordpress-to-facebook/
Thanks for your help Blake.
So now that facebook has listed it as a TOS violation, how many people are still using it? Will you plan to continue using it or is it back to the drawing board? I’m keen to get it working too, away from the windows platform.
I just joined the party a few days too late!
[…] than fighting this out and took down the code; Facebook has since reactivated his account. Several others who had used his code also caved and took down their […]
[…] than fighting this out and took down the code; Facebook has since reactivated his account. Several others who had used his code also caved and took down their […]
wow thanks, i had never heard of twitterberry before. Took only a minute to get working and it’s great!
Thanks!
[…] to pull down, my C# code I had to pull down (about which I also posted a comment this week), and the others who did. you can read what they wrote about it at […]
[…] months ago Christian discovered a hack to change your Facebook status. Some other people also used it and extended it. I also ported it to C# and made a winform using its unofficial method. Suddenly after, Facebook […]
[…] controversial topic about difficulty of Facebook status updates is now quite simple. You can view and change your […]
[…] Google searches on this topic, so here is the answer, and it’s called Stats2Site. I myself like to use Twitter, but I realize that not everyone likes to do that (thank goodness I care about […]
I figured out how to do this using only facebook apps. Check it out:
http://www.wikihow.com/Synchronize-Your-Facebook-Status-and-Twitter-Using-Only-Facebook-Apps
[…] than fighting this out and took down the code; Facebook has since reactivated his account. Several others who had used his code also caved and took down their […]