2017-04-13 96 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); 

但這不再出現在文檔。