Invite Friends API

One of the most common features of social games built on the Facebook platform is the ability for players to invite their friends to play the game with them.

Unforchinatly, the Invitable Friends API is only available to apps classified as Games, which also have a Canvas presence. This API is not available in v1.0. It may be called by mobile games as long as they also have a Canvas presence.

Meaning, it is ONLY possible for games, if your App is NOT a game you can forget about it. And you MUST have a Canvas implementation next to your mobile one. Meaning, you can´t just create a Canvas App that redirects (which would not be allowed), you would have to create a game that actually runs on Canvas too.

Detailed information about Canvas Apps can be found in the docs. Thx, to luschn for making  it clear via StackOverflow post.

How event we can steel use AppRequest, which can be used for sending the invites by SendInvite method of SPFacebook class 

public void SendInvite(string title, string message, string data = "", string[] to = null)

 

The code snippet bellow shows how to send invite and allow user to select the recipients via Facebook default dialog box.

string title = "Hello";
string message = "Play with me";

SPFacebook.instance.SendInvite(title, message);
SPFacebook.instance.OnAppRequestCompleteAction += OnAppRequestCompleteAction;


void OnAppRequestCompleteAction (FBAppRequestResult result) {

	if(result.IsSucceeded) {
		Debug.Log("App request succeeded");
		Debug.Log("ReuqetsId: " + result.ReuqestId);
		foreach(string UserId in result.Recipients) {
			Debug.Log(UserId);
		}

		Debug.Log("Original Facebook Responce: " + result.Result.Text);
	} else {
		Debug.Log("App request has failed");
	}
	SPFacebook.instance.OnAppRequestCompleteAction -= OnAppRequestCompleteAction;
}

 

 

We may also provide more info like, specified recipients (in this case friends selector dialog will not be showed) or add the additional request data.

string FriendId = "1405568046403868";
string title = "Hello";
string message = "Play with me";

//Additional freeform data you may pass for tracking. This will be stored as part of the request objects created. The maximum length is 255 characters. (Optional) 
string requestDate = "some_request_data";

SPFacebook.instance.SendInvite(title, message, requestDate, new string[]{FriendId});
SPFacebook.instance.OnAppRequestCompleteAction += OnAppRequestCompleteAction;


void OnAppRequestCompleteAction (FBAppRequestResult result) {

	if(result.IsSucceeded) {
		Debug.Log("App request succeeded");
		Debug.Log("ReuqetsId: " + result.ReuqestId);
		foreach(string UserId in result.Recipients) {
			Debug.Log(UserId);
		}

		Debug.Log("Original Facebook Responce: " + result.Result.Text);
	} else {
		Debug.Log("App request has failed");
	}
	SPFacebook.instance.OnAppRequestCompleteAction -= OnAppRequestCompleteAction;
}

 

Handling request's is similar with the another request type. But since we can not use full Facebook invite API FBAppRequestActionType  in the FBAppRequest will remain Undefined. Requests handeling described in follwowing chapters:

You can read more about the Facebook App requests at the Facebook Official Documentation. The implementation example can be found at the FacebookTurnBasedAndGifts example scene.