symfony2 and facebook share button - facebook

i'm working on a web app, and I added a facebook like/share button by following this tutorial. I was wondering, is there a way to catch the event in the controller, if someone shares the page ?

If you're only trying to retrieve data passively (ie. just count the likes or retrieve the cookie of the liker), you can catch the click event with JS and make an ajax call to your controller.
To completely catch the event and tweak it before sending it to FB, you can hack the behaviour of the button to make it point directly to your controller, and then send the request to facebook yourself via your own custom method.
The code generated by FB's like buttons is not that simple though, so I would stick to the first method if I were you.

Related

callback on foursquare like and follow buttons

Is it possible to have a callback URL on foursquare Web buttons when they have been successfully clicked?
Is it as simple as just including a redirect_url attribute in the html?
You can try capturing the click event client-side and using that information as you wish.

How do I make content on a html page visable only to users who have pressed the like button on that page?

On my website I want visitors only to be able to access some content after they have shared my website on facebook by pressing the like button. I want to know how I can make content visable only to users who have pressed the like button.
There's a couple of methods to this approach, neither of which are going to get you 100% of what you want.
edge.create
You can listen for edge.create event, through FB.Event.subscribe. When that's fired, you can remove a display:none attribute from a div or similar element. The downside to that is that your hidden content would still be visible to anyone who viewed the source.
The other option on that edge.create event is that you could pull in the content via AJAX, which will keep it out of your source until the event is fired.
The problem with the whole edge.create event is that once someone re-visits your page, the edge.create event won't detect that the person already likes your website, so the hidden content won't get displayed.
user_likes
The way around that is to request the user_likes permission. Once you have that, you can call /me/likes/<your_page_id> using the JS-SDK. If we return an empty array, they don't like the page and you wouldn't load the content. If they do, we'll return data on the page, so you'd display it.
The problem with that approach is that you'll need to use Facebook Login. Nothing wrong with that in general, but the trade-off is a drop in conversions, which might not be worth it just to hide some content, but that's up to you.

Can't access ViewBag data in Facebook App

I have a Facebook app that is giving me fits. I basically have an app that once the user has liked the app, they can continue through the app. Using the Facebook Javascript API, it will see if the user has logged in, and if not allow them to log in. I pass rather or not they "like" the page from the controller, as well as their language (English or Spanish) to the view via the ViewBag object.
This works both locally and from the staging server; however I have to disable the like check in the view, but the language and like is passed in the viewbag.
I placed language in the view like
<p>The user's language is #ViewBag.lang</p>
and
<p>They like the page? #ViewBag.likes
Like I said, both locally and at the staging server it works; but nothing gets passed through to the Facebook app. I have a conditional check to see if the user likes the page in javascript like:
var likes = #ViewBag.likes
In Facebook, using the console I see that the data isn't passed as well as the before mentioned debugging I tried doing.
I am very new to MVC; is there something I need to enable to make it work through Facebook?
Thanks!
Well the issue is that the Facebook canvas sends an initial POST, this was hitting my POST instead of the GET which was setting these values. See here:
Does Facebook open a canvas app with a Post request? It's causing havoc with my MVC actions
Thanks!

What method throws "You must like the page"

I'm doing my first steps in FB Apps using the Javascript API but I stumble upon this Top Gear page and I would like to know what method throws this message as I had to make a if statement in php that would use the
$like_status = $signed_request["page"]["liked"];
from the PHP Library (really would love to do all in Javascript, really) to show a <fb:like> button and then subscribe up to the edge.create event in order to show the app it self...
I think was to much trouble if I could at least perform this technique as a simple call.
This article has what you are looking for. Facebook will send post variables to your page with anonymous info about the user including their language and whether they are a fan or not. Once they like the page, the page will refresh and you will know that they are a fan, so you won't need to subscribe to edge.create methods. You will have a variable server side that indicates whether they are a fan and you can code from there.

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.