为什么Facebook发布批处理失败的GraphBatchException - #0?

时间:2014-10-27 23:31:13

标签: c# facebook facebook-graph-api facebook-c#-sdk

以下是我用于使用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);

如果我注释掉三个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

1 个答案:

答案 0 :(得分:0)

这是C#Facebook SDK的错误。如果总请求超过999个字符,则无法正确编码。

https://github.com/facebook-csharp-sdk/facebook-csharp-sdk/issues/315