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.
精彩评论