Question

How would I do this but using Graph API to grab locale and display content based on country?.

FB.login(function(response) {
             if data.get('user').get('locale') = "en_GB" {
                $("#footer a").text("URL HERE");
            }
        });
Was it helpful?

Solution

If you're using the facebook javascript sdk for authenticating the user, then you get a signed request for the user, as it states in the signed request guide:

When using the JS SDK for authentication, the authResponse object contains a signed_request property which is used to transfer information about the authenticated user.

The signed request has the user field which is:

A JSON object containing the locale string, country string and the age object (containing the min and max number range of the age) for the current user

You should get the locale value even if the user hasn't authenticated your app so that you could show content that matches it.


Edit

You have a few ways to get the authResponse, the most basic of which is to use FB.login, like so:

FB.login(function(response) {
    if (response.authResponse) {
        console.log(response.authResponse);
    }
    else {
        console.log(response);
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top