我有一个奇怪的问题。
我有一串广告组ID。它被逗号分割。
我使用了facebook的graph api explorer
来获取所有这些广告的总花费。
所以我称之为:
act_ACOUNTID/adgroupstats?adgroup_ids=[AD_GROUP_IDS]&start_time=
2009-05-18T07:00:00&end_time=2014-05-19T07:00:00&limit=100&offset=100
在结果中有42行(总行数为142,但我使用offset
(从第100行获取)和limit
(仅显示第100行)所以有没问题)。
在我的视觉中,我打了同样的电话:
int ADS_LIMIT = 100;
int offset = 100;
IDictionary<string, object> result = facebookClient.Get("/act_" + accountId +
"/adgroupstats?adgroup_ids=[" + adGroupIds + "]&start_time=" + startTime +
"&end_time=" + endTime + "&limit=" + ADS_LIMIT + "&offset=" + offset, parameters)
as IDictionary<string, object>;
var DataResult = result["data"] as List<object>;
但DataResult.Count
包含100行而不是42行。
有人猜到为什么会出现这个问题吗? (p.s.我将代码中的字符串复制并粘贴到facebook图表api中并设置访问令牌以便它没有问题)
任何帮助表示赞赏!
答案 0 :(得分:6)
facebook为此问题回答了我:
In this case this is not a bug and is in fact by design. Limit and Offset
pagination is not supported across all endpoints and in the Ads API we recommend
that you instead use the "next" & "previous" paging links. This is highlighted
here:
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.0#paging
答案 1 :(得分:1)
(供将来参考:)正如你所说的那样,要解决类似问题的第一件事就是查看结果字符串。
在你的情况下:
Console.WriteLine("Created String: " +
"/act_" + accountId +
"/adgroupstats?adgroup_ids=[" + adGroupIds + "]" +
"&start_time=" + startTime +
"&end_time=" + endTime +
"&limit=" + ADS_LIMIT +
"&offset=" + offset);
facebookClient.Get(..)
方法究竟做了什么...... 这可能是一个非常令人痛苦的问题,因为你并不总是有调试的来源,或者更糟糕的是当你的SDK的请求以不同的方式处理时,比直接的api调用和你几乎无法解决问题。 (除了报告或询问SO ^^)