I am trying to get the user’s locale but I am having trouble doing so. My App has been approved by facebook to use the user_location permission.
In my script I request the permission with: permissions.Add(“user_location”);
then
FB.API(“/me?fields=location”, HttpMethod.GET, DisplayLocation);
void DisplayLocation(IResult result)
{
if (result.ResultDictionary.ContainsKey(“locale”))
{
FacebookLocation = result.ResultDictionary[“locale”];
PlayerPrefs.SetString(“location”, FacebookLocation.ToString());
}
}
However, I keep getting the error that locale isn’t in the dictionary. I’ve also tried replacing locale with hometown but get the same error. I am using the same code to get gender, name etc. and that all works fine.
Here is the full error:
KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[System.String,System.Object].get_Item (System.String key) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
facebook.DisplayLocation (IResult result) (at Assets/Scripts/facebook.cs:272)
Facebook.Unity.AsyncRequestString+c__Iterator1.MoveNext () (at Assets/FacebookSDK/SDK/Scripts/Utils/AsyncRequestString.cs:133)