문제

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");
            }
        });
도움이 되었습니까?

해결책

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);
    }
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top