Facebook – Share button/post to wall – Facebook API

facebookfacebook-graph-api

I don't want to use the FB like button and apparently "share" has been deprecated.
What I am trying to do is have users click "share"/"post to wall" from my website, and it then places a post on their newsfeed/profile with information on my website/url.

I can't seem to find any code around that will do this- does anyone have an example?

And do they have to connect first? Or can it check if they're logged in, if not, login and it shares automatically?

Thanks!

Best Answer

This is possible in two ways:

  • You can use the facebook Javascript SDK if you have an app:
    FB.ui({
        method: 'feed',  
        link: 'absolute url',
        name: 'testtitle',
        caption: 'testcaption',
        description: 'testdescription',
        picture: 'absolute picurl',
        message: ''
    });

Note that "message" MUST be empty, you can also just remove it.

  • Without an app (no user can block the app and never get anything from the app anymore, but only possible with popup): open a popup window with Javascript for the facebook sharer:

    http://www.facebook.com/sharer.php?u=<url to share>&t=<title of content>
    

    Note that everything needs to be urlencoded. Of course you can also just use it as a link. And don't forget the og tags in this case.

Edit: Please be aware that "auto sharing" is not allowed on facebook. you have to present the user what you want to share in his name and he has to be able to accept it and add his personal message. would only be possible with an app and an authorized user anyway.

Btw, both methods explained here work without user login/authorization.

Edit2: There is also a "share" method with FB.ui now, to post a link or use Open Graph Actions/Objects.