2014-10-27 43 views
2

這裏是我使用的C#的Facebook的SDK 6.8.0從的NuGet測試配料代碼:爲什麼Facebook發佈批次與GraphBatchException - #0失敗?

var client = new FacebookClient(); 
client.AppId = application.FacebookAppId; 
client.AppSecret = application.FacebookAppSecret; 

var batchedRequests = new List<FacebookBatchParameter>(); 
batchedRequests.Add(new FacebookBatchParameter() 
{ 
    HttpMethod = HttpMethod.Post, 
    Path = "2982XXXXXXXXXX001/feed", 
    Parameters = new Dictionary<string, object> 
    { 
     {"access_token", "CAAK9UGtbUaMBAKX..."}, 
     {"message", "Check out our stuff at Google: " + DateTime.UtcNow.Ticks}, 
     {"link", "http://www.google.com"} 
    } 
}); 
batchedRequests.Add(new FacebookBatchParameter() 
{ 
    HttpMethod = HttpMethod.Post, 
    Path = "755XXXXXXXXXX21/photos", 
    Parameters = new Dictionary<string, object> 
    { 
     {"access_token", "CAAK9UGtbUaMBAA6..."}, 
     {"message", "Lions, oh my! " + DateTime.UtcNow.Ticks}, 
     {"url", "http://i.imgur.com/DVSsmpa.jpg"} 
    } 
}); 
batchedRequests.Add(new FacebookBatchParameter() 
{ 
    HttpMethod = HttpMethod.Post, 
    Path = "2982XXXXXXXXXX001/feed", // Same as first 
    Parameters = new Dictionary<string, object> 
    { 
     {"access_token", "CAAK9UGtbUaMBAKX..."}, // Same as first 
     {"message", "Check out our stuff at Facebook: " + DateTime.UtcNow.Ticks}, 
     {"link", "http://www.facebook.com"} 
    } 
}); 

var batchedParams = new Dictionary<string, object>(); 
batchedParams.Add("access_token", defaultPage.PageAccessToken); 

dynamic facebookResponse = client.Batch(batchedRequests.ToArray(), batchedParams); 

如果我註釋掉三個batchedRequests.Add()中的任何一個要求,它工作正常。

只有三者在一起纔會被打破。

這是我得到的錯誤:

Unhandled Exception: Facebook.FacebookApiException: (GraphBatchException - #0) Batch parameter must be a JSON array 
    at Facebook.FacebookClient.ProcessResponse(HttpHelper httpHelper, String responseString, Type resultType, Boolean containsEtag, IList`1 batchEtags) 
    at Facebook.FacebookClient.Api(HttpMethod httpMethod, String path, Object parameters, Type resultType) 
    at Facebook.FacebookClient.Post(String path, Object parameters) 
    at Facebook.FacebookClient.Post(Object parameters) 
    at Facebook.FacebookClient.Batch(FacebookBatchParameter[] batchParameters, Object parameters) 
    at FacebookTest.Program.FacebookBatchTest() in c:\Test\Program.cs:line 81 
    at FacebookTest.Program.Main(String[] args) in c:\Test\Program.cs:line 23 
+0

的錯誤意味着你的批次不正確編碼/包/序列化 - 你調試嗎? – Igy 2014-10-27 23:34:39

+0

它一次只能運行一個或兩個記錄,但全部3個都會導致失敗。我不確定此時需要包裝什麼。 – Kcoder 2014-10-27 23:42:35

+0

我懷疑這可能是FacebookClient.Batch()方法如何處理請求的問題,但不幸的是,我沒有任何可見性來查看傳遞給Facebook的URL調用。 – Kcoder 2014-10-27 23:48:26

回答

相關問題