I have a web app where the same object can have multiple URL's depending on the locale parameter, like so:
http://domain.com/{_locale}/{id}/{slug}
I have a Like button on those pages, which works just fine, but the problem is that Likes done in each locale count as a separate OpenGraph object since the URL is different.
The obvious solution would be to use an object id instead of just the href parameter of the Like button, but it seems like it may not be possible.
Basically, I need a way for a Like to count for both:
http://domain.com/fr/1/some-slug
and
http://domain.com/en/1/some-slug
Because they are, after all, both the same object.
Any ideas?
I guess I had to type it out to figure it out. Here's my solution for Symfony2.
The way I got it to work was to tweak my existing
localeAction
. By default, it was triggered by going to the root of the website, but I changed it so it accepts a route and parameters:Then, I created a route configuration specifically for Facebook:
In that controller I find the object by id, get the slug from the database and forward to the locale controller which will take care of detecting the user's locale and redirect accordingly.
Lastly, the view can use the new route for the like button like so:
Which results in the following
href
:http://domain.com/fb/profile/1
I found out it is important to set the og:url meta tag like so:
Which results in the following
content
:http://domain.com/fr/profile/1/some-slug
Notice this is the real URL, if I used the Facebook route here, the debugger whined about circular redirection. Oh and the button didn't work either.
I could have used the slug in the Facebook route, but if the slug changes for one reason or another, it would destroy all the existing Likes for this object, which is obviously not a desirable side effect.
That's it!
and
Are now the same object in the eyes of Facebook.