为什么Facebook帖子批处理失败,出现GraphBatchException-#0
本文关键字:出现 GraphBatchException-#0 失败 批处理 Facebook 为什么 | 更新日期: 2023-09-27 18:28:12
以下是我使用NuGet:中的C#Facebook SDK 6.8.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);
如果我注释掉三个batchedRequest.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
这是C#Facebook SDK的一个错误。如果总请求长度超过999个字符,则无法正确编码。
https://github.com/facebook-csharp-sdk/facebook-csharp-sdk/issues/315