2016-02-12 74 views
0

我拉我原來的問題,因爲我設法通過蹤跡和錯誤和大量深入的搜索找出它。 所以,據我所知,在統一採用最新的Facebook SDK,您可以用拉爲玩家所有掛起的請求:Facebook團結和處理應用程序請求

FB.API("/me/apprequests", HttpMethod.GET, RequestHandler) 

凡RequestHandler是IGraphResult,然後你可以解析成一個字典,像這樣:

void RequestHandler(IGraphResult result){ 
    if (result != null) { 
     Dictionary<string, object> reqResult = Json.Deserialize(result.RawResult) as Dictionary<string, object>; 
    } 

}

文檔解釋瞭如何一個奇異的請求將會以JSON格式顯示,並且但是如果我發現瞭如何處理這些信息的工作(我隱約明白JSON的)幾個例子,拉所有對玩家的要求,我如何處理這些信息?

在JSON之外,我只是試圖拉取每個請求的對象ID和發送者ID,根據對象ID處理請求,然後通過連接兩個圖來從圖中刪除請求,我認爲我已經找到了。

所以我的問題是,對於每個請求,我如何提取對象和發件人ID?

回答

0

所以試錯和大量的日誌檢查了很多之後,我想通了,不知道這樣做,對於那些一個真正哈克的方式:

public void TestRequests(){ 
    FB.API("/me/apprequests", HttpMethod.GET, TestResponse); 
} 

public void TestResponse(IGraphResult result){ 
    if (result.Error == null) { 
     //Grab all requests in the form of a dictionary. 
     Dictionary<string, object> reqResult = Json.Deserialize(result.RawResult) as Dictionary<string, object>; 
     //Grab 'data' and put it in a list of objects. 
     List<object> newObj = reqResult["data"] as List<object>; 
     //For every item in newObj is a separate request, so iterate on each of them separately. 
     for(int xx = 0; xx < newObj.Count; xx++){ 
      Dictionary<string, object> reqConvert = newObj[0] as Dictionary<string, object>; 
      Dictionary<string, object> fromString = reqConvert["from"] as Dictionary<string, object>; 
      Dictionary<string, object> toString = reqConvert["to"] as Dictionary<string, object>; 
      string fromName = fromString["name"] as string; 
      string fromID = fromString["id"] as string; 
      string obID = reqConvert["id"] as string; 
      string message = reqConvert["message"] as string; 
      string toName = toString["name"] as string; 
      string toID = toString["id"] as string; 
      Debug.Log ("Object ID: " + obID); 
      Debug.Log ("Sender message: " + message); 
      Debug.Log ("Sender name: " + fromName); 
      Debug.Log ("Sender ID: " + fromID); 
      Debug.Log ("Recipient name: " + toName); 
      Debug.Log ("Recipient ID: " + toID); 
     } 
    } 
    else { 
     Debug.Log ("Something went wrong. " + result.Error); 
    } 
} 

同樣,這是我第一次使用JSON的經驗,我確信有這樣做的更有效的方法,但基本上經過了很多分解和轉換後,我設法提取對象ID,發件人名稱和ID,消息附件和收件人姓名和ID。對象ID與接收者ID連接在一起,因此爲了在對象ID本身上進行操作,需要將其刪除,因爲它將更容易傳遞字符串以從Graph API中刪除請求。

如果任何人都可以向我建議一個更有效的方法來做到這一點,我將不勝感激!畢竟,總是有更多的東西要學。