English 中文(简体)
Facebook: any way to monitor when user clicks on Like button?
原标题:

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 box 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.





相关问题
Facebook Connect login dialog not working

I am using Facebook Connect for iPhone and following the official instructions. I use the following code to display the login dialog: FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:...

Facebook App Profile Tab is Empty ... No Content Displayed?

I can view my application via the http://apps.facebook.com/myapplication/ link and the content shows up correctly. I also added the application as a tab to a facebook page. However, when viewing the ...

Facebook Platform error: "Object cannot be liked"

I m working on a Facebook Application that generates wall posts. In testing these posts, I ve discovered that the Facebook Platform action of "liking" a post is failing. The specific error message ...

how to call showPermissionsDialog() in php (facebook api)?

I was reading over the documentation yet I could not figure out how to call Facebook.showPermissionsDialog() in php include_once ./facebook-platform/php/facebook.php ; $facebook = new Facebook(my ...

Facebook connect

If I plug in the facebook connect into my website, How can I prevent double signups? Lets say I have a user that s already signed up to my site but he clicked the connect with facebook, is there a ...

热门标签