Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Dictionary error with Facebook SDK

Discussion in 'Android' started by zigglr, May 30, 2016.

  1. zigglr

    zigglr

    Joined:
    Sep 28, 2015
    Posts:
    82
    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)
     
  2. babji3

    babji3

    Joined:
    May 28, 2015
    Posts:
    179
    same error, did u solved??