如何在Bing Ads中更新广告系列?

时间:2016-08-29 07:38:01

标签: c# ads bing bing-api

对于更新广告系列,我使用此代码

public async Task<List<long?>> updateCampaign(Campaign campaign,string status)
    {
        try
        {
            campaign.Status = (CampaignStatus)(int)Enum.Parse(typeof(CampaignStatus), status);
            var request = new UpdateCampaignsRequest
            {
                Campaigns = new Campaign[] { campaign },
                CustomerId = "xxxxxx",
                UserName = "something@outlook.com",
                Password = "something@123",
                ApplicationToken = "myApplicationToken",
                CustomerAccountId = "123456",
                DeveloperToken = "1234567890"
            };

            CampaignService = new ServiceClient<ICampaignManagementService>(_authorizationData);
            CampaignService.RefreshOAuthTokensAutomatically = false;
            var result = (await CampaignService.CallAsync((s, r) => s.UpdateCampaignsAsync(r), request));

            if (result.TrackingId != null)
            {
                return result.CampaignIds.ToList();
            }
            else
            {
                return new List<long?>();
            }
        }
        catch (Exception ex)
        {
            ErrorLog.log(ex);
            return new List<long?>();
        }
    }

当我运行此代码时,我收到此错误“无效的客户端数据。请查看SOAP错误详细信息以获取更多信息”

感谢。

1 个答案:

答案 0 :(得分:1)

要更新广告系列,我们可以使用“BulkServiceManager”批量更新广告系列,您也可以使用此服务单一广告系列更新。

public async Task<List<long?>> updateCampaign(List<Campaign> campaigns)
    {
        try
        {
            var listBulkCampaign = new List<BulkCampaign>();
            foreach (var campaign in campaigns)
            {
              var _bulkCampaign = new BulkCampaign()
                {
                    Campaign = campaign
                };
                listBulkCampaign.Add(_bulkCampaign);
            }
            BulkServiceManager bulkServiceManager = new BulkServiceManager(_authorizationData);
            string fileName = bingCampaignUpdate.csv;
            var campaigns = (await bulkServiceManager.UploadEntitiesAsync(new EntityUploadParameters
            {
                Entities = listBulkCampaign,
                OverwriteResultFile = true,
                ResultFileDirectory = FileDirectory,
                ResultFileName = fileName,
                ResponseMode = ResponseMode.ErrorsAndResults
            })).OfType<BulkCampaign>().ToList();

            return new List<long?>();
        }
        catch (Exception ex)
        {
            ErrorLog.log(ex);
            return new List<long?>();
        }
}

您必须下载.csv报告并更新广告系列。

我希望它可以帮到你