Facebook & Twitter Share Customized Text
I wanted to allow users to easily share content that they had input into a page onto Facebook and Twitter. Good news and bad news: It's pretty easy to set up the Tweet, but Facebook won't allow you to prepopulate a status message. The best you can do there is share your URL.
To kick things off, I created this example:
What is your favorite color?
As you can see, it's nothing fancy. Here's the code behind it:
The Tweet button use's Twitter's Tweet Web Intent method to share the user's favorite color and the URL of the page.
The Share button uses Facebook's Share Dialog but, as I mentioned earlier, there's no way there of prepopulating the status message. So, while we're able to share the URL, we're not able to share the user's favorite color.
(There is a potential workaround here by setting up multiple URLs using query strings and then sharing those… page.html?color=pink, page.html?color=blue, for example. But that wasn't an exact match of what I was trying to do here, so I didn't pursue it.)
As it is, we'll use have to let the users come up with their own message for Facebook; all we can provide is the URL.
One note of caution: Be sure to update your Facebook App ID before using the code shown here.