Monday, February 27, 2012

Facebook Share (URL based)

This is the most simplest way to add a facebook share button.

Use the following code as the reference(href) attribute of your anchor tag(<a>)

"http://www.facebook.com/sharer.php?u=<text or url to post on wall>"

You can use any image to show the share button, but be precise in selecting it,

as the user should get on it easily.

Consider the following sample code:

<a href="http://www.facebook.com/sharer.php?u=https://thechaithanya.wordpress.com"><img src="http://www.acrnet.org/uploadedImages/Get_Involved/facebook-logo.png" alt="share on facebook"></a>

If you are developing any applicetion or website and want the post to be displayed as it was posted from your app,

like "via theChaithanya", use the following code:

         "http://m.facebook.com/dialog/feed?app_id=YOUR-APP-ID&link=LINK-TO-BE-POSTED&redirect_uri=PATH-TO-LOCATION-AFTER-SHARE"

On successful sharing it will redirect you to the redirect-url along with post-id.

Note: To get APP-ID, you have to register a developer account and create an app.

Also the redirect url should be added there in the app settings.

For further info visit: https://developers.facebook.com/