开发者

Facebook: any way to monitor when user clicks on Like button?

开发者 https://www.devze.com 2022-12-29 06:39 出处:网络
writing my first facebook webapp and i have some questions. I\'m using their new Graph API + JS library.

writing my first facebook webapp and i have some questions. I'm using their new Graph API + JS library.

The idea is that in order to use my webapp, user has to 'Like' facebook page A.

Suppose user is logged in. I have to check if he 'likes' page A. If user doesn't like that page, i display 'fan b开发者_StackOverflowox' via

FB.XFBML.parse('<fb:fan profile_id="A's id" stream="0" connections="0" width="450"></fb:fan>');

Now, this fan box with 'Like' button is rendered in iframe that has src set to facebook domain.

Problem: i want to know when user clicks on 'Like' button so that i can display the rest of my webapp. The only possible solution that i can think of is polling every second facebook graph server which is really bad.

  • i can't attach 'onClick' event on that button cause it's inside iframe pointed to facebook domain (can't access it at all using JS)
  • i tried getting the contents of this iframe from my server and display it in iframe with empty src property so that i can access its elements - doesn't work, fan box is messed up.
  • There is no way that i know of to send 'i want to like that page' request to Graph server on behalf of the user.

I'm stumped. I really doubt that polling is the right way to solve this problem :)


You can get the onclick event by using the fbml code of like button instead of iframe code.

Facebook provides FB.event.subscribe which triggers when somebody clicks like button.

A complete tutorial is here.In your case you can write the code to refresh the page on like button click. and check for like condition on page load. so that if current user has liked the page you can redirect him to application page.

0

精彩评论

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