Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I decided to leave out <code>authResponse</code> caching and call <code>FB.login()</code> every time. It briefly opens a popup window, but at least there's no case where user has logged out in another tab or window and the cached <code>authResponse</code> has gone stale. The briefly flashing popup window is not that big of an issue, since I don't think users will share the same page multiple times, anyway.</p> <p>Here's my final code which is even simpler than the original one:</p> <pre><code>&lt;button id="fb-publish"&gt;Share to Facebook&lt;/button&gt; &lt;script type="text/javascript"&gt; (function() { FB.init({ appId: MY_FACEBOOK_APP_ID, cookie: true, status: true, xfbml: true, oauth: true }); var fbShare = function() { FB.ui({ method: "feed", display: "iframe", link: "http://example.com/", caption: "Example.com", description: "Here is the text I want to share.", picture: "http://example.com/image.png" }); }; $("#fb-publish").click(function() { FB.login(function(response) { if (response.authResponse) { fbShare(); } }, {scope: 'publish_stream'}); }); })(); &lt;/script&gt; </code></pre> <p>And as mentioned by Tolga Arican, if it's ok to you that the sharing dialog opens in a popup window, you don't even need to call <code>FB.login()</code> and ask for the <code>publish_stream</code> permission; just call <code>FB.ui({ method: "feed" })</code> directly and you're good to go:</p> <pre><code>&lt;button id="fb-publish"&gt;Share to Facebook&lt;/button&gt; &lt;script type="text/javascript"&gt; (function() { FB.init({ appId: MY_FACEBOOK_APP_ID, cookie: true, status: true, xfbml: true, oauth: true }); $("#fb-publish").click(function() { FB.ui({ method: "feed", link: "http://example.com/", caption: "Example.com", description: "Here is the text I want to share.", picture: "http://example.com/image.png" }); }); })(); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload