Search code examples
c#facebookunity3d-guiunity-game-engine

Unity3d AppRequest invite limit on select


I have problem with FB.AppRequest. I need the user to only select one friend from the list shown in the Facebook UI, but I can't find a way to do it looking at the Facebook Unity3d SDK.

Thanks for the help.

public void ShareWithUsers()
{
    FB.AppRequest(

        "Come and join me, i bet u cant beat my score",
        null,
        new List<object>() {"app_users"},
        null,
        null,
        null,
        null,
        ShareWithUsersCallback

    );
}

void ShareWithUsersCallback(IAppRequestResult result)
{   
    if (result.Cancelled)
    {
        Debug.Log("Challenge Cancel");
        GameObject.Find("CallBacks").GetComponent<Text>().text = "Challenge Cancel";
    }
    else if (!String.IsNullOrEmpty(result.Error))
    {
        Debug.Log("Challenge on error");
        GameObject.Find("CallBacks").GetComponent<Text>().text = "Challenge on error";
    }
    else if (!String.IsNullOrEmpty(result.RawResult))
    {
        Debug.Log("Success on challenge");

    }
}

Solution

  • If you look at the documentation for FB.AppRequest it explains that the fourth parameter is the "to".

    public static void AppRequest(
        string message, 
        OGActionType actionType,
        string objectId,
        IEnumerable<string> to,
        string data = "",
        string title = "",    
        FacebookDelegate<IAppRequestResult> callback = null
    )
    

    Where to is a list of Facebook IDs to which to send the request, if you leave it null like now the sender will be shown a dialog allowing him/her to choose the recipients.

    So in your case you can leave it null and let the user choose, or if it has already chosen (you already know which friend he wants to challenge) then you will need to create a list and add his Facebook ID.

    FB.AppRequest(
    
            "Come and join me, i bet u cant beat my score",
            null,
            new List<object>() {"app_users"},
            new List<string>() {"[id of your friend]"},
            null,
            null,
            null,
            ShareWithUsersCallback
    
        );
    

    Either way this line new List<object>() {"app_users"} means that the request can be sended to someone who already plays the game. But if you remove it it could be send to any of his friends.

    I have seen some older code that set a maxRecipients which would allow you, if setted to one, to be sure that the user selects only one friend through the UI:

    FB.AppRequest(
            string message,
            IEnumerable<string> to = null,
            IEnumerable<object> filters = null,
            IEnumerable<string> excludeIds = null,
            int? maxRecipients = null,
            string data = "",
            string title = "",
            FacebookDelegate<IAppRequestResult> callback = null);
    

    But this no longer appears in the documentation.