2017-04-13 99 views
0

我有FB.AppRequest问题。我需要用户只从Facebook用户界面中显示的列表中选择一个朋友,但我无法找到一种方法来查看Facebook Unity3d SDK。Unity3d AppRequest限制选择

感谢您的帮助。

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"); 

    } 
} 
+0

检查你是如何在你的代码中编写“挑战”和“成功”的,你可能要考虑用相同的格式编写所有的调试日志,如:“挑战取消”,“挑战错误”和“挑战成功” 。 – moondaisy

回答

1

如果你看一下文档FB.AppRequest它解释说,第四个参数是“对”。

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

哪里to是向其发送请求的Facebook ID的列表,如果你把它null像现在发件人将显示一个对话框,让他/她选择收件人。

所以你的情况,你可以把它null并让用户选择,或者如果它已经选择了(你已经知道他要挑战它的朋友),那么你需要创建一个列表,并添加自己的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 

    ); 

无论哪种方式这条线new List<object>() {"app_users"}意味着可以将请求sended的人谁已经玩游戏。但是如果你删除它,它可能会发送给他的任何朋友。

我看到some older code确立了maxRecipients这样可以让你,如果设置好的一个,以确保用户通过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); 

但这不再出现在文档。