开发者

callback for add-to-timeline plugin?

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 permi开发者_Python百科ssion.

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?


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);
        }
      });
  }  
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜