Facebook SDK for Unity: How to check if an invite has been sent?

That’s pretty much it.

I want to reward the player if he/she sends one or a specified number of invitations. I assume for overall in between sessions you’d have to store it somewhere on the web. But for now I just wanna count the invites sent in the current session for simplicity’s sake, so it doesn’t have to be stored on the web.

Now naturally its easy to check if the user pressed a button that calls the FB.AppRequest() function, and count that, but he can easily press cancel without inviting anyone.

So how can I know if an invite has been sent? I can’t find it in any of the reference or examples. And I’m pretty new to this and can’t find ANY tutorials other than the official ones.

Thanks!

In your callback function you can do the following

if(result != null)
{
    // get the list of users invited
    var responseObject = Json.Deserialize(result.Text) as Dictionary<string, object>;
    
    // get the amount of users invited and convert to an integer
    IEnumerable<object> invitesSent = (IEnumerable<object>)responseObject["to"];
    int numberOfInvites = invitesSent.Count;
    
    // for every user invited, do something
    for(int i = 1; i <= numberOfInvites; i++)
    {
      // do something
    }
}

don’t forget to include System.Linq to access the Count method.

Hi im doing the same thing i did something like this
I added :
using System.Linq;
using Facebook.MiniJSON;
couse Json.deserialize wasnt seen by monodevelop.
Question is am i doing it right? Im also quite new to this and i want to inf FB.API() get FBResult as aresult set in InvitesCallback function and then check it. Am doing it righ or something? Thanks for response :slight_smile:

	public void InviteFriends()
	{
		FB.AppRequest (
			message: " This game is awesome, join me.",
			title: " Invite your friends to join the challenge"
		);
		GetInvitations ();
	}

	public void GetInvitations()
	{
		FB.API(
	}

	public void InvitesCallBack(FBResult result)
	{
		if (result != null) {
			// get the list of users invited
			var responseObject = Json.Deserialize (result.Text) as Dictionary<string, object>;

			// get the amount of users invited and convert to an integer
			IEnumerable<object> invitesSent = (IEnumerable<object>)responseObject ["to"];
			int numberOfInvites = invitesSent.Count;
			
			// for every user invited, do something
			if (numberOfInvites > 5) 
			{
				AdBlocker = 1;
				PlayerPrefs.SetInt("AdBlocker", "AdBlocker");
				PlayerPrefs.Save();
			}
			Debug.Log("Invited"+ numberOfInvites);
		}
	}