Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share button/post to wall - Facebook 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!

like image 268
Gazzzzza Avatar asked Sep 09 '11 03:09

Gazzzzza


People also ask

How do I share a Facebook post with API?

Yes, you can share using the graph2 api. The way you do it is to use /feed edge and pass the post's url that you want to share as the link. Standard Fb permissions to the post you are sharing do apply. This was done today, in a local rails app, using FbGraph2 gem, with the above method.


1 Answers

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.

like image 64
andyrandy Avatar answered Oct 26 '22 13:10

andyrandy