Facebook的基于C#的Marketing-API-/ setsets问题

时间:2019-04-11 13:36:36

标签: c# facebook api webclient

我有一个问题。.这里有任何Marketing-API专家吗?我试图编写一个基于C#的API来创建/ campaigns,/ adsets和/ ads。使用/ campaigns,我没有问题,启动项目后,创建的/ campaign将显示在我的广告系列管理器中。但是以某种方式,它不适用于创建/ adsets。我收到来自Visual Studio的400错误请求。有人知道创建/ adset所需的字段吗?

预先感谢!

string campaign_id = "8890374892378023";

NameValueCollection request_parameter = new NameValueCollection();
request_parameter.Add("name", "TestAdSet");
request_parameter.Add("optimization_goal", "REACH");
request_parameter.Add("billing_event", "IMPRESSIONS");
request_parameter.Add("bid_strategy", "LOWEST_COST_WITHOUT_CAP");
request_parameter.Add("is_autobid", "true");
request_parameter.Add("lifetime_budget", "1000000");
request_parameter.Add("campaign_id", campaign_id);
request_parameter.Add("targeting", "{'geo_locations':{'countries': ['DE']}},{'publisher_platforms': ['all']}, {'facebook_positions': ['all']},{'device_platforms': ['all']}");
request_parameter.Add("promoted_object", "{'page_id': ['78686786786786']}");
request_parameter.Add("start_time", "2019-04-11T15:00:17+0000");
request_parameter.Add("end_time", "2019-04-15T04:45:17+0000");
request_parameter.Add("status", "PAUSED");
request_parameter.Add("access_token", access_token);

byte[] responsebytes = client.UploadValues("https://graph.facebook.com/v3.2/act_" + ad_account_id + "/adsets", "POST", request_parameter);
string result = Encoding.UTF8.GetString(responsebytes);

string adset_id = Regex.Match(result, "[0-9]+").Value;

Console.Write(result);
Console.Read();

1 个答案:

答案 0 :(得分:0)

request_parameter.Add("targeting", "{'geo_locations':{'countries': ['DE']}},{'publisher_platforms': ['all']}, {'facebook_positions': ['all']},{'device_platforms': ['all']}");

不正确,因为第二个字符串不是有效的JSON。使用前,请务必检查https://jsonlint.com中的字符串,以确保其有效。