如何解决Google Ad-Manager API客户端库.Net:创建新的ListItem时出现“ ServerError.SERVER_ERROR”
请过去曾在Google广告管理器API中遇到此问题的人。我正在尝试为我的广告管理器创建一个新的LineItem,但是在调用lineItemService.createLineItems(lineItems)时出现ServerError.SERVER_ERROR。
我不知道我在做什么错,我在下面添加了我的代码,以及一些我得到的错误的屏幕截图。
public static LineItem[] CreateLineItem(Order order,AdvertItem[] items)
{
AdManagerUser adUser = new AdManagerUser();
using (LineItemService lineItemService = adUser.GetService<LineItemService>())
{
// Create an array to store local line item objects.
LineItem[] lineItems = new LineItem[items.Length];
for (int i = 0; i < items.Length; i++)
{
LineItem lineItem = new LineItem
{
name = items[i].Title,orderId = order.id,targeting = new targeting()
};
int numberOfDays = (items[i].EndDate - items[i].StartDate).Days;
decimal amountPerDay = (items[i].Estimatedcost / numberOfDays) * 1000000;
lineItem.lineItemType = LineItemType.STANDARD;
lineItem.allowOverbook = true;
// Set the creative rotation type to even.
lineItem.creativeRotationType = CreativeRotationType.EVEN;
// Set the size of creatives that can be associated with this line item.
Size size = new Size
{
width = items[i].Width,height = items[i].Height,isAspectRatio = false
};
// Create the creative placeholder.
CreativePlaceholder creativePlaceholder = new CreativePlaceholder
{
size = size,};
lineItem.creativePlaceholders = new CreativePlaceholder[]
{
creativePlaceholder
};
// Set the line item to run for one month.
lineItem.startDateTime = DateTimeUtilities.FromDateTime(items[i].StartDate,"America/New_York");
lineItem.endDateTime = DateTimeUtilities.FromDateTime(items[i].EndDate,"America/New_York");
// Set the cost per unit to $2.
lineItem.costType = CostType.CPM;
lineItem.costPerUnit = new Money
{
currencyCode = "GBP",microAmount = Convert.ToInt64(amountPerDay)
};
Geotargeting geotargeting = new Geotargeting();
// Include the UK
Location countryLocation = new Location
{
id = 2826L
};
// Create day-part targeting.
DayParttargeting dayParttargeting = new DayParttargeting
{
timeZone = DeliveryTimeZone.broWSER
};
geotargeting.targetedLocations = new Location[]
{
countryLocation
};
long[] targetPlacementIds = new long[1];
targetPlacementIds[0] = 22081065438;
// Create inventory targeting.
Inventorytargeting inventorytargeting = new Inventorytargeting();
inventorytargeting.targetedplacementIds = targetPlacementIds;
lineItem.targeting.inventorytargeting = inventorytargeting;
lineItem.targeting.geotargeting = geotargeting;
lineItem.targeting.dayParttargeting = dayParttargeting;
Goal goal = new Goal
{
goalType = GoalType.LIFETIME,unitType = UnitType.UNKNowN,units = 500000L
};
lineItem.primaryGoal = goal;
LineItem[] lineItemToSave = new LineItem[1];
lineItemToSave[0] = lineItem;
//create
try
{
// Create the line items on the server.
var savedLineItems = lineItemService.createLineItems(lineItemToSave);
if (savedLineItems != null && savedLineItems.Length > 0 )
{
lineItems[i] = savedLineItems[0];
}
else
{
Console.WriteLine("No line items created.");
}
}
catch (Exception e)
{
Console.WriteLine("Failed to create line items. Exception says \"{0}\"",e.Message);
}
}
if (lineItems.Length > 0)
{
return lineItems;
}
return null;
}
}[ServerError.SERVER_ERROR][1]
当我运行上面的代码并点击api时,我得到“ ServerError.SERVER_ERROR”
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。