1

When a user comes to my website and tries to allow publish_action permission, he will click on the 'add-to-timeline' plugin button.
Then a popup dialog appears and user will allow the required permission.
What I want to find out is that if we can specify any callback function to invoke after user allows the permission.

I know we can subscribe to 'edge.create' event through FB.Event.subscribe, but I couldn't find a similar solution for 'add-to-timeline'.
At least, it wasn't written on its document as far as I read.
Can somebody help me?

hadees
  • 1,754
  • 2
  • 25
  • 36
Oklahomer
  • 896
  • 9
  • 24

1 Answers1

3

You can subscribe to the global events to accomplish this.

If you subscribe to auth.login, auth.authResponseChange, or auth.statusChange they will be called after the user authorized your application via 'add-to-timeline'.

So for example you could do this...

FB.Event.subscribe('auth.login', function(response) {
  alert('The user has just authorized your application');
});

However I'm guessing what you want is the same thing that I wanted which is to have the action added to the timeline after the user clicks 'add-to-timeline' the first time and then on subsequent visits to your site just have it added to the timeline automatically.

To do that you would do this...

/** put your FB.init right here **/

FB.Event.subscribe('auth.statusChange', function(response) {
  if (response.status == 'connected') {
    FB.api("/me/foobar:watch" + "?video=http://foobar.com/video/123","post",
      function(response) {
        if (!response || response.error) {
          alert("Error");
        } else {
          alert("Post was successful! Action ID: " + response.id);
        }
      });
  }  
});
hadees
  • 1,754
  • 2
  • 25
  • 36