Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook meta tags scraped with locale not working

My website is multi-language and I have a FB like button. I'd like to have the like posts in different languages.

According to Facebook documentation, if I use the meta tag og:locale and og:locale:alternate, the scraper would get my site info passing the parameter "locale" and the header "X-Facebook-Locale", but it's not sending neither.(https://developers.facebook.com/docs/beta/opengraph/internationalization/). So the posts end always in en_US.

Anyone having the same problem?

like image 491
Alouw Net Avatar asked Sep 30 '11 18:09

Alouw Net


2 Answers

I got this working. The documentation is not very detailed; here are details.

Here are my Open Graph locale tags:

<meta property="og:locale" content="en_US" />
<meta property="og:locale:alternate" content="en_US" />
<meta property="og:locale:alternate" content="fr_CA" />

VERY IMPORTANT: The documentation makes it seem that og:locale should always reflect the page's "default" locale. This is not the case; doing so will prevent the scraper from retrieving other languages. og_locale must reflect the page's current locale. In other words, if the scraper (or the user) requests fr_CA content, make sure og_locale is set to fr_CA in the response.

Specify all possible locales with og:locale:alternate. This way, whether the scraper asked for en_US or fr_CA, it still knows that both exist.

Here's me asking the Facebook scraper to re-process my page:

curl -d "id=https://apps.facebook.com/everydaybarilla/&scrape=true" https://graph.facebook.com

Here's the response:

{
   "url": "http://apps.facebook.com/everydaybarilla/",
   "type": "website",
   "title": "Barilla\u2019s Every Day, Every Way Contest",
   "locale": {
      "locale": "en_us",
      "alternate": [
         "fr_ca"
      ]
   },
   "image": [
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/5.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/4.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/3.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/en-2.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/en-1.png"
      }
   ],
   "description": "Barilla Canada is whisking one lucky winner and a guest off to Italy on an 8-day Italian culinary adventure for 2 in the Barilla Every Day, Every Way Contest!",
   "site_name": "Barilla\u2019s Every Day, Every Way Contest",
   "updated_time": "2012-04-16T17:59:38+0000",
   "id": "10150594698421968",
   "application": {
      "id": "317271281656427",
      "name": "Barilla\u2019s Every Day, Every Way Contest",
      "url": "http://www.facebook.com/apps/application.php?id=317271281656427"
   }
}

The scraper correctly returns the data for the default locale, but according to the documentation, it seems that the scraper should scrape alternate locales as well; this is not the case. Clearly from the response above it sees the alternate locales, but it does not process them.

So, here's me specifically asking the Facebook scraper to process my page en français:

curl -d "id=https://apps.facebook.com/everydaybarilla/&scrape=true&locale=fr_CA" https://graph.facebook.com

This time, I correctly see two requests to my server from the scraper. The second request has both the X-Facebook-Locale header and the fb_locale URL parameter correctly set to fr_CA. And the POST correctly returns the French response:

{
   "url": "http://apps.facebook.com/everydaybarilla/?fb_locale=fr_CA",
   "type": "website",
   "title": "Concours Tous les jours, de toutes les fa\u00e7ons de Barilla",
   "locale": {
      "locale": "fr_ca",
      "alternate": [
         "en_us",
         "fr_ca"
      ]
   },
   "image": [
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/5.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/4.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/3.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/fr-2.png"
      },
      {
         "url": "http://everydaybarilla.ssl.spidermarketing.ca/assets/img/thumbnails/fr-1.png"
      }
   ],
   "description": "Un heureux gagnant et son invit\u00e9(e) partiront \u00e0 destination de l\u2019Italie pour une aventure culinaire de 8 jours pour 2 personnes (valeur au d\u00e9tail approximative de 15 000 $)!",
   "site_name": "Barilla\u2019s Every Day, Every Way Contest",
   "updated_time": "2012-04-16T18:11:27+0000",
   "id": "10150594698421968",
   "application": {
      "id": "317271281656427",
      "name": "Barilla\u2019s Every Day, Every Way Contest",
      "url": "http://www.facebook.com/apps/application.php?id=317271281656427"
   }
}

Success!

Of course, after all this effort, when I go to the French Facebook.com and post this URL, the status box is populated… with the English data. It seems Facebook's own interfaces aren't configured to request the correct locale.

So even with all this effort, nothing seems to have been accomplished (translations of my strings via the Facebook translation app aren't working either, so I guess I shouldn't be surprised).

Still, it does answer the question. Perhaps somebody else can determine why the Facebook.com interfaces don't seem to request the correct locale.

like image 111
Aaron Adams Avatar answered Nov 14 '22 04:11

Aaron Adams


Facebook's locale handling is completely inconsistent

After wrestling with open graph locales for weeks now, I managed to post content with changing texts based on user's locale. For the links though, I'm still unable to get the expected results.

Here are my observations:

og:locale in the debugger shows by default, my actual facebook locale. Clicking on the og:locale:alternate links changes object properties as well as the interface language. I think it's by design.

The 'Raw Open Graph Document Information' section, without fb_locale appended to the input URL, shows the default data. If the fb_locale is set and in mixed case, Raw Open Graph Document Information section is changed according to the parameter. The 'Object properties' section still shows data based on actual / selected locale. If fb_locale is in lowercase, it returns 'Error parsing input URL, no data was scraped.'

The same thing is true for the 'locale' parameter appended to the debugger's (not the input) URL. If it's in mixed case format, Object Properties section and the interface language is changed. However, it does nothing when I pass it in lowercase (returns default/current locales)

Surprisingly, the graph api is acting inversely:

  1. when I request a re-scrape with php sdk

    1. the content is updated only when locale is passed in lowercase, but(!) in this case, the response returned doesn't have locale:locale parameter, which is set if either X-Facebook locale header or fb_locale parameter were present.

      All data in the response is in default locale. However, the wall post is updated and text is displayed correctly according to my facebook locale settings.

    2. if the locales are passed in mixed case format - as defined is the documentation -, request returns 'unsupported post request' error. When using php CURL function instead of the Facebook php SDK's api call, en_GB is an exception, where the response contains fb_locale and localized (english) content as well, but, the object properties / wall posts aren't updated, neither for en_GB. For other languages, 'Unspported post request' is returned.

  2. When I use the object's id (the id found on the bottom of the debugger page - by querying the 'comments_fbid' field from 'link_stat' table) instead of the URL:

    1. with mixed case locales, the response contains correct text and fb_locale for all locales, but none of them are updated. og:updated_time is unchanged in the debugger, but it's updated on https://graph.facebook.com/[object ID]

    2. with lower case locales, the result is the same as described in 1.1.

  3. In graph queries, the behaviour is again the opposite of the above: When I try to query https://graph.facebook.com/[object ID]?locale=en_GB, with mixed-case locales, it returns the expected result, with lower-case locales, it returns the default version with no locale (only locale:alternate) tags set. :-o

Is it possible that the graph api endpoint and the debugger treats the locales differently, making it impossible to get the same reponse from both?

btw with lower case locales, I managed to have localized posts on the feed, where the text is displayed based on the uer's locale.

Now my problem is that all links are pointing to the same canonical URL without any locale-specific information, because - as Salvador said -doing so would create different objects. See my post here: how to get the locale of a facebook user clicking on a localised object's link?

like image 3
Balázs Ágasvári Avatar answered Nov 14 '22 04:11

Balázs Ágasvári