- Home /
Please can someone help me get user's country using Facebook API
I have been trying to get the user's country using the Facebook API, but I keep getting an error.
permissions.Add("user_location");
FB.API("/me?fields=location", HttpMethod.GET, DisplayLocation);
void DisplayLocation(IResult result)
{
FacebookLocation = result.ResultDictionary["user_location"];
PlayerPrefs.SetString("location", FacebookLocation.ToString());
}
However it keeps giving an 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:220) Facebook.Unity.AsyncRequestString+c__Iterator1.MoveNext () (at Assets/Facebook/Scripts/Utils/AsyncRequestString.cs:132)
Please can someone kindly give some advice? Thanks!
Answer by gokhan.ozdemir · May 27, 2016 at 04:59 PM
hi, you are add new permission but i think the problem is solved this way : re-login after the add new permission.
permissions.Add("user_location");
FB.LogInWithReadPermissions(permissions,AuthCallback);
FB.API("/me?fields=location", HttpMethod.GET, DisplayLocation);
void DisplayLocation(IResult result)
{
FacebookLocation = result.ResultDictionary["user_location"];
PlayerPrefs.SetString("location", FacebookLocation.ToString());
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612080359im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Error using Facebook API to get user's birthday (given key not present in dictionary) 1 Answer
How to enable the application events (sdk facebook). 0 Answers
CommandInvokationFailure: Unable to convert classes into dex format. 1 Answer
WebCamTexture conflicts with Facebook Audience Network - Unity SDK 0 Answers