Hey. I am trying to query my Mongo database using a list of Facebook IDs as a parameter to return a list of users with matching accounts. The method works fine in the Unity editor, but when I run it on iOS, I get a constructor error (I installed an empty default constructor to solve the problem, however it still doesn't work)
Initial method
public void FetchData()
{
if (FB.IsLoggedIn)
{
FB.API("me/friends", HttpMethod.GET, FriendsHighscoreHndlr);
}
}
Callback method
public void FriendsHighscoreHndlr (IGraphResult FBresult){
var dict = Json.Deserialize(FBresult.ToString()) as Dictionary<string,object>;
var friendList = new List<object>();
friendList = (List<object>)(dict["data"]);
int _friendCount = friendList.Count;
Debug.Log("Found friends on FB, _friendCount ... " +_friendCount);
List<string> friendIDsFromFB = new List<string>();
for (int i=0; i<_friendCount; i++) {
string friendFBID = getDataValueForKey( (Dictionary<string,object>)(friendList[i]), "id");
string friendName = getDataValueForKey( (Dictionary<string,object>)(friendList[i]), "name");
Debug.Log( i +"/" +_friendCount +" " +friendFBID +" " +friendName);
friendIDsFromFB.Add(friendFBID);
}
var query = Query.In("facebookID", BsonArray.Create(friendIDsFromFB));
data = Mongo.Instance.players.Find(query).ToList();
}
Data Value for Key Method
private string getDataValueForKey(Dictionary<string, object> dict, string key) {
object objectForKey;
if (dict.TryGetValue(key, out objectForKey)) {
return (string)objectForKey;
} else {
return "";
}
}
Request Return Result
{
"_id" : ObjectId("XXXXXX"),
"facebookID" : "XXXXXXXXXXXXXX",
"name" : "John Doe",
"highScore" : 40501
}
source
share