1

I cant figure out why facebook publish is not working on this site

I get

API Error Code: 102 API Error Description: Session key invalid or no longer valid Error Message: Iframe dialogs must be called with a session key

While calling the stream.publish method as iframe

<script type="text/javascript">

    (function() {
      var e = document.createElement('script'); e.async = true;
      e.src = document.location.protocol 
        + '//connect.facebook.net/fr_FR/all.js';
      document.getElementById('fb-root').appendChild(e);
    }());


    window.fbAsyncInit = function()
    {
      FB.init({     appId: '303380259758621',
            status: true,
            channelUrl: 'http://www.crabegame.com/channel.php',
            cookie: true,
            xfbml: true,
            oauth: true});

    }


    function PublishStream(score)
    {
        FB.ui(
        {
            method: 'stream.publish',
            display    : 'iframe',
            message    : '',
            attachment:
            {
            name: 'CrabeGame',
            caption: 'Essaye de battre mon score sur le Crabe Game !',
            description: "J'ai réalisé un score de " + score  +  "points au Crabe Game !",
            href: 'http://www.crabegame.com',
            media:
            [
                {
                type: 'image',
                src: 'http://crabegame.com/media/crabe_fb.png',
                href: 'http://www.crabegame.com'
                }
            ]
            },
            action_links:
            [
            {
                text: 'Play Crabe Game',
                href: 'http://www.crabe-game.com'
            }
            ],
            user_message_prompt: 'Publier sur votre mur'
        },
        function (response)
        {
            if (response && response.post_id)
            {

            }
        }
        );
    }
</script>
Nico AD
  • 1,657
  • 4
  • 31
  • 51
  • [This question](http://stackoverflow.com/questions/7373355/api-error-code-102-javascript-dialogs-with-php) and the accepted answer may be relevant. – nickie Jan 03 '14 at 13:43

2 Answers2

0

This means that you have no current user. Try this in order to call PublishStream:

     FB.login(function(response) {
         if (response.authResponse) {
             PublishStream();
         } else {
             console.log('Not logged in');
         }
      });
Stephen Woods
  • 4,049
  • 1
  • 16
  • 27
0

you don´t need a logged in user, just remove display: "iframe", worked for me. it will still show in an iframe, but without error. don´t ask me why, with 1:1 the same app settings it works WITH the display value in another app of mine...at least that worked for me with the apprequest dialog, might be the same here.

and i would use "feed" instead of "stream.publish".

see here: https://developers.facebook.com/docs/reference/dialogs/feed/

also: Using Like Button and FB.ui (apprequests) On the Same Page Conflicts

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • why the downvotes? stream.publish IS deprecated, for example. so at least some of my infos are correct. – andyrandy Mar 23 '13 at 01:35