- Home /
Facebook SDK for Unity: check if an invite has been sent and give award to the player
I'm using this script to check if the player has sent an invitation to his friends and then give him a reward.
the script is commented .
this is what I get as a result : it means that there is something wrong with this line IEnumerable invitesSent = (IEnumerable)responseObject["to"]; please read the script it is commented
I'm running on android public void ChalengeFriends () { FB.AppRequest ( "Here is a free gift!", null, new List (){ "app_users" }, null, null, "data", "Challenge your friends!", ChalengeFriendsCallBack1 ); }
void ChalengeFriendsCallBack1 (IAppRequestResult result)
{
if (result.Cancelled) {
} else if (!string.IsNullOrEmpty (result.Error)) {
} else {
text5.text = " challenge success : " + result.RawResult;
text5.text = "1=== "+text5.text;
/* //method 1 : not working
IDictionary<string,object> data = result.ResultDictionary;
text5.text = "2=== "+text5.text;
List<object> friends = (List<object>)data ["to"]; //something wrong here
text5.text = "3";
text5.text = "" + friends.Count;
if (friends.Count == 2) {
// Give user a free item
text5.text = "reward success------" + friends.Count;
//.........
}*/
// method 2 : not working
var responseObject = Json.Deserialize(result.RawResult) as Dictionary<string, object>;
text5.text = "3=== "+text5.text; // the execution stops at this line
IEnumerable<object> invitesSent = (IEnumerable<object>)responseObject["to"];
// List<string> objectArray = (List<string>)responseObject["to"]; //not working
text5.text = "4=== "+text5.text;
if (objectArray.Count() == 1)
{
// Give user a free item
text5.text = "reward yeeeeeeeeeeeees------" +objectArray.Count();
}
}
}
Answer by wenderRondonia · Oct 25, 2017 at 09:20 PM
If anyone is still searching here is an example in comments: http://answers.unity3d.com/questions/668192/facebook-sdk-for-unity-how-to-check-if-an-invite-h.html
Your answer
Follow this Question
Related Questions
Parsing Json from facebook? 1 Answer
Parse Json Response through Dictionary object 1 Answer
Facbook Authentication token 0 Answers
Deserialize Facebook friends result 1 Answer
Parsing a JSON response 1 Answer