问题描述
请过去曾在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 (将#修改为@)