本文整理汇总了C#中Google.Api.Ads.Dfp.Lib.DfpUser.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# DfpUser.GetService方法的具体用法?C# DfpUser.GetService怎么用?C# DfpUser.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google.Api.Ads.Dfp.Lib.DfpUser
的用法示例。
在下文中一共展示了DfpUser.GetService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user)
{
ReportService reportService = (ReportService) user.GetService(
DfpService.v201403.ReportService);
// Get the NetworkService.
NetworkService networkService = (NetworkService) user.GetService(
DfpService.v201403.NetworkService);
// Get the root ad unit ID to filter on.
String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;
// Create statement to filter on an ancestor ad unit with the root ad unit ID to include all
// ad units in the network.
StatementBuilder statementBuilder = new StatementBuilder(
"where AD_UNIT_ANCESTOR_AD_UNIT_ID = :ancestorAdUnitId").
AddValue("ancestorAdUnitId", long.Parse(rootAdUnitId));
// Create report query.
ReportQuery reportQuery = new ReportQuery();
reportQuery.dimensions =
new Dimension[] { Dimension.AD_UNIT_ID, Dimension.AD_UNIT_NAME };
reportQuery.columns = new Column[] {Column.AD_SERVER_IMPRESSIONS,
Column.AD_SERVER_CLICKS, Column.DYNAMIC_ALLOCATION_INVENTORY_LEVEL_IMPRESSIONS,
Column.DYNAMIC_ALLOCATION_INVENTORY_LEVEL_CLICKS,
Column.TOTAL_INVENTORY_LEVEL_IMPRESSIONS,
Column.TOTAL_INVENTORY_LEVEL_CPM_AND_CPC_REVENUE};
// Set the filter statement.
reportQuery.statement = statementBuilder.ToStatement();
reportQuery.adUnitView = ReportQueryAdUnitView.HIERARCHICAL;
reportQuery.dateRangeType = DateRangeType.LAST_WEEK;
// Create report job.
ReportJob reportJob = new ReportJob();
reportJob.reportQuery = reportQuery;
try {
// Run report.
reportJob = reportService.runReportJob(reportJob);
// Wait for report to complete.
while (reportJob.reportJobStatus == ReportJobStatus.IN_PROGRESS) {
Console.WriteLine("Report job with id = '{0}' is still running.", reportJob.id);
Thread.Sleep(30000);
// Get report job.
reportJob = reportService.getReportJob(reportJob.id);
}
if (reportJob.reportJobStatus == ReportJobStatus.COMPLETED) {
Console.WriteLine("Report job with id = '{0}' completed successfully.", reportJob.id);
} else if (reportJob.reportJobStatus == ReportJobStatus.FAILED) {
Console.WriteLine("Report job with id = '{0}' failed to complete successfully.",
reportJob.id);
}
} catch (Exception ex) {
Console.WriteLine("Failed to run inventory report. Exception says \"{0}\"",
ex.Message);
}
}
示例2: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user)
{
// Get the InventoryService.
InventoryService inventoryService =
(InventoryService) user.GetService(DfpService.v201302.InventoryService);
// Get the NetworkService.
NetworkService networkService =
(NetworkService) user.GetService(DfpService.v201302.NetworkService);
string effectiveRootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;
// Create an array to store local ad unit objects.
AdUnit[] adUnits = new AdUnit[5];
for (int i = 0; i < 5; i++) {
AdUnit adUnit = new AdUnit();
adUnit.name = string.Format("Ad_Unit_{0}", i);
adUnit.parentId = effectiveRootAdUnitId;
adUnit.description = "Ad unit description.";
adUnit.targetWindow = AdUnitTargetWindow.BLANK;
// Set the size of possible creatives that can match this ad unit.
Size size = new Size();
size.width = 300;
size.height = 250;
// Create ad unit size.
AdUnitSize adUnitSize = new AdUnitSize();
adUnitSize.size = size;
adUnitSize.environmentType = EnvironmentType.BROWSER;
adUnit.adUnitSizes = new AdUnitSize[] {adUnitSize};
adUnits[i] = adUnit;
}
try {
// Create the ad units on the server.
adUnits = inventoryService.createAdUnits(adUnits);
if (adUnits != null) {
foreach (AdUnit adUnit in adUnits) {
Console.WriteLine("An ad unit with ID = '{0}' was created under parent with " +
"ID = '{1}'.", adUnit.id, adUnit.parentId);
}
} else {
Console.WriteLine("No ad units created.");
}
} catch (Exception ex) {
Console.WriteLine("Failed to create ad units. Exception says \"{0}\"", ex.Message);
}
}
示例3: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user)
{
// Get the PlacementService.
PlacementService placementService =
(PlacementService) user.GetService(DfpService.v201208.PlacementService);
// Get the InventoryService.
InventoryService inventoryService =
(InventoryService) user.GetService(DfpService.v201208.InventoryService);
// Create a statement to select first 500 placements.
Statement filterStatement = new Statement();
filterStatement.query = "LIMIT 500";
try {
// Get placements by statement.
PlacementPage page = placementService.getPlacementsByStatement(filterStatement);
if (page.results != null) {
Placement[] placements = page.results;
// Update each local placement object by enabling AdSense targeting.
foreach (Placement placement in placements) {
placement.targetingDescription = (string.IsNullOrEmpty(placement.description))?
"Generic description" : placement.description;
placement.targetingAdLocation = "All images on sports pages.";
placement.targetingSiteName = "http://code.google.com";
placement.isAdSenseTargetingEnabled = true;
}
// Update the placements on the server.
placements = placementService.updatePlacements(placements);
// Display results.
if (placements != null) {
foreach (Placement placement in placements) {
Console.WriteLine("A placement with ID \"{0}\", name \"{1}\", and AdSense targeting" +
" enabled \"{2}\" was updated.", placement.id, placement.name,
placement.isAdSenseTargetingEnabled);
}
} else {
Console.WriteLine("No placements updated.");
}
}
} catch (Exception ex) {
Console.WriteLine("Failed to update placements. Exception says \"{0}\"",
ex.Message);
}
}
示例4: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user)
{
// Get the UserService.
UserService userService = (UserService) user.GetService(DfpService.v201211.UserService);
// Sets defaults for page and Statement.
UserPage page = new UserPage();
Statement statement = new Statement();
int offset = 0;
try {
do {
// Create a Statement to get all users.
statement.query = string.Format("LIMIT 500 OFFSET {0}", offset);
// Get users by Statement.
page = userService.getUsersByStatement(statement);
if (page.results != null && page.results.Length > 0) {
int i = page.startIndex;
foreach (User usr in page.results) {
Console.WriteLine("{0}) User with ID = '{1}', email = '{2}', and role = '{3}'" +
" was found.", i, usr.id, usr.email, usr.roleName);
i++;
}
}
offset += 500;
} while (offset < page.totalResultSetSize);
Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
} catch (Exception ex) {
Console.WriteLine("Failed to get all users. Exception says \"{0}\"",
ex.Message);
}
}
示例5: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user) {
// Get the PlacementService.
PlacementService placementService =
(PlacementService) user.GetService(DfpService.v201211.PlacementService);
// Create a Statement to only select active placements.
Statement statement = new StatementBuilder("WHERE status = :status LIMIT 500").AddValue(
"status", InventoryStatus.ACTIVE.ToString()).ToStatement();
try {
// Get placements by Statement.
PlacementPage page = placementService.getPlacementsByStatement(statement);
// Display results.
if (page.results != null && page.results.Length > 0) {
int i = page.startIndex;
foreach (Placement placement in page.results) {
Console.WriteLine("{0}) Placement with ID = '{1}', name ='{2}', and status = '{3}' " +
"was found.", i, placement.id, placement.name, placement.status);
i++;
}
}
Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
} catch (Exception ex) {
Console.WriteLine("Failed to get placement by Statement. Exception says \"{0}\"",
ex.Message);
}
}
示例6: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user) {
// Get the ForecastService.
ForecastService forecastService =
(ForecastService) user.GetService(DfpService.v201502.ForecastService);
// Set the line item to get a forecast for.
long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE"));
try {
// Get forecast for line item.
AvailabilityForecastOptions options = new AvailabilityForecastOptions();
options.includeContendingLineItems = true;
options.includeTargetingCriteriaBreakdown = true;
AvailabilityForecast forecast =
forecastService.getAvailabilityForecastById(lineItemId, options);
// Display results.
long matched = forecast.matchedUnits;
double availablePercent = (double) (forecast.availableUnits / (matched * 1.0)) * 100;
String unitType = forecast.unitType.ToString().ToLower();
Console.WriteLine("{0} {1} matched.\n{2} % {3} available.", matched, unitType,
availablePercent, unitType);
if (forecast.possibleUnitsSpecified) {
double possiblePercent = (double) (forecast.possibleUnits / (matched * 1.0)) * 100;
Console.WriteLine(possiblePercent + "% " + unitType + " possible.\n");
}
Console.WriteLine("{0} contending line items.", (forecast.contendingLineItems != null)?
forecast.contendingLineItems.Length : 0);
} catch (Exception ex) {
Console.WriteLine("Failed to get forecast by id. Exception says \"{0}\"", ex.Message);
}
}
示例7: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user) {
// Get the ContactService.
ContactService contactService =
(ContactService) user.GetService(DfpService.v201505.ContactService);
// Set the ID of the contact to update.
long contactId = long.Parse(_T("INSERT_CONTACT_ID_HERE"));
try {
StatementBuilder statementBuilder = new StatementBuilder()
.Where("id = :id")
.OrderBy("id ASC")
.Limit(1)
.AddValue("id", contactId);
// Get the contact.
ContactPage page = contactService.getContactsByStatement(statementBuilder.ToStatement());
Contact contact = page.results[0];
// Update the address of the contact.
contact.address = "123 New Street, New York, NY, 10011";
// Update the contact on the server.
Contact[] contacts = contactService.updateContacts(new Contact[] {contact});
// Display results.
foreach (Contact updatedContact in contacts) {
Console.WriteLine("Contact with ID \"{0}\", name \"{1}\", and comment \"{2}\" was " +
"updated.", updatedContact.id, updatedContact.name, updatedContact.comment);
}
} catch (Exception ex) {
Console.WriteLine("Failed to update contacts. Exception says \"{0}\"", ex.Message);
}
}
示例8: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user) {
// Get the NetworkService.
NetworkService networkService =
(NetworkService) user.GetService(DfpService.v201308.NetworkService);
// Set the networkCode field to null to retrieve all networks you have
// access to.
networkService.RequestHeader.networkCode = null;
try {
// Get all networks that you have access to with the current login
// credentials.
Network[] networks = networkService.getAllNetworks();
int i = 0;
foreach (Network network in networks) {
Console.WriteLine("{0} ) Network with network code \"{1}\" and display name \"{2}\" " +
"was found.", i + 1, network.networkCode, network.displayName);
i++;
}
Console.WriteLine("Number of networks found: {0}", i);
} catch (Exception ex) {
Console.WriteLine("Failed to get all networks. Exception says \"{0}\"",
ex.Message);
}
}
示例9: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user)
{
// Get the LabelService.
LabelService labelService =
(LabelService) user.GetService(DfpService.v201208.LabelService);
// Create a statement to only select labels that are competitive
// sorted by name.
Statement filterStatement = new StatementBuilder("WHERE type = :type ORDER BY name LIMIT 500")
.AddValue("type", LabelType.COMPETITIVE_EXCLUSION.ToString()).ToStatement();
try {
// Get labels by statement.
LabelPage page = labelService.getLabelsByStatement(filterStatement);
if (page.results != null) {
int i = page.startIndex;
foreach (Label label in page.results) {
StringBuilder builder = new StringBuilder();
foreach (LabelType labelType in label.types) {
builder.AppendFormat("{0} | ", labelType);
}
Console.WriteLine("{0}) Label with ID '{1}', name '{2}'and type '{3}' was found.",
i, label.id, label.name, builder.ToString().TrimEnd(' ', '|'));
i++;
}
}
Console.WriteLine("Number of results found: " + page.totalResultSetSize);
} catch (Exception ex) {
Console.WriteLine("Failed to get labels. Exception says \"{0}\"", ex.Message);
}
}
示例10: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user)
{
// Get the ContentService.
ContentService contentService =
(ContentService) user.GetService(DfpService.v201403.ContentService);
// Set defaults for page and filterStatement.
ContentPage page = new ContentPage();
Statement filterStatement = new Statement();
int offset = 0;
try {
do {
// Create a statement to get all content.
filterStatement.query = "LIMIT 500 OFFSET " + offset.ToString();
// Get content by statement.
page = contentService.getContentByStatement(filterStatement);
if (page.results != null) {
int i = page.startIndex;
foreach (Content content in page.results) {
Console.WriteLine("{0}) Content with ID \"{1}\", name \"{2}\", and status \"{3}\" " +
"was found.", i, content.id, content.name, content.status);
i++;
}
}
offset += 500;
} while (offset < page.totalResultSetSize);
Console.WriteLine("Number of results found: " + page.totalResultSetSize);
} catch (Exception ex) {
Console.WriteLine("Failed to get all content. Exception says \"{0}\"", ex.Message);
}
}
示例11: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user) {
// Get the TeamService.
TeamService teamService = (TeamService) user.GetService(DfpService.v201208.TeamService);
// Create a statement to order teams by name.
Statement filterStatement = new StatementBuilder("ORDER BY name LIMIT 500").ToStatement();
try {
// Get teams by statement.
TeamPage page = teamService.getTeamsByStatement(filterStatement);
// Display results.
if (page.results != null) {
int i = page.startIndex;
foreach (Team team in page.results) {
Console.WriteLine("{0}) Team with ID \"{1}\" and name \"{2}\" was found.",
i, team.id, team.name);
i++;
}
}
Console.WriteLine("Number of results found: " + page.totalResultSetSize);
} catch (Exception ex) {
Console.WriteLine("Failed to get teams by statement. Exception says \"{0}\"", ex.Message);
}
}
示例12: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user) {
// Create the CreativeWrapperService.
CreativeWrapperService creativeWrapperService = (CreativeWrapperService) user.GetService(
DfpService.v201502.CreativeWrapperService);
long creativeWrapperId = long.Parse(_T("INSERT_CREATIVE_WRAPPER_ID_HERE"));
try {
StatementBuilder statementBuilder = new StatementBuilder()
.Where("id = :id")
.OrderBy("id ASC")
.Limit(1)
.AddValue("id", creativeWrapperId);
CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(
statementBuilder.ToStatement());
CreativeWrapper wrapper = page.results[0];
wrapper.ordering = CreativeWrapperOrdering.OUTER;
// Update the creative wrappers on the server.
CreativeWrapper[] creativeWrappers = creativeWrapperService.updateCreativeWrappers(
new CreativeWrapper[] {wrapper});
// Display results.
foreach (CreativeWrapper createdCreativeWrapper in creativeWrappers) {
Console.WriteLine("Creative wrapper with ID '{0}' and wrapping order '{1}' was " +
"updated.", createdCreativeWrapper.id, createdCreativeWrapper.ordering);
}
} catch (Exception ex) {
Console.WriteLine("Failed to update creative wrappers. Exception says \"{0}\"",
ex.Message);
}
}
示例13: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user) {
// Get the AudienceSegmentService.
AudienceSegmentService audienceSegmentService =
(AudienceSegmentService) user.GetService(DfpService.v201306.AudienceSegmentService);
// Set defaults for page and Statement.
AudienceSegmentPage page = new AudienceSegmentPage();
Statement statement = new Statement();
int offset = 0;
try {
do {
// Create a Statement to get all creatives.
statement.query = string.Format("LIMIT 500 OFFSET {0}", offset);
// Get audience segment by Statement.
page = audienceSegmentService.getAudienceSegmentsByStatement(statement);
// Display results.
if (page.results != null && page.results.Length > 0) {
int i = page.startIndex;
foreach (AudienceSegment segment in page.results) {
Console.WriteLine("{0}) 'Audience segment with id \"{1}\" and name \"{2}\" was " +
"found.", i, segment.id, segment.name);
i++;
}
}
offset += 500;
} while (offset < page.totalResultSetSize);
Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
} catch (Exception ex) {
Console.WriteLine("Failed to get audience segment. Exception says \"{0}\"", ex.Message);
}
}
示例14: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user) {
// Get the UserService.
UserService userService = (UserService) user.GetService(DfpService.v201403.UserService);
// Create a Statement to get all active users sorted by name.
StatementBuilder statementBuilder = new StatementBuilder()
.Where("status = :status")
.OrderBy("name ASC")
.Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
.AddValue("status", "ACTIVE");
// Set default for page.
UserPage page = new UserPage();
try {
do {
// Get users by Statement.
page = userService.getUsersByStatement(statementBuilder.ToStatement());
if (page.results != null && page.results.Length > 0) {
int i = page.startIndex;
foreach (User usr in page.results) {
Console.WriteLine("{0}) User with ID = '{1}', email = '{2}', and role = '{3}'" +
" was found.", i, usr.id, usr.email, usr.roleName);
}
}
statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.GetOffset() < page.totalResultSetSize);
Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
} catch (Exception ex) {
Console.WriteLine("Failed to get user by ID. Exception says \"{0}\"",
ex.Message);
}
}
示例15: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="user">The DFP user object running the code example.</param>
public override void Run(DfpUser user) {
// Get the LineItemService.
LineItemService lineItemService =
(LineItemService) user.GetService(DfpService.v201311.LineItemService);
// Set the ID of the order to get line items from.
long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));
// Create a statement to only select line items that need creatives from a
// given order.
Statement filterStatement =
new StatementBuilder("WHERE orderId = :orderId AND status = :status LIMIT 500")
.AddValue("orderId", orderId)
.AddValue("status", ComputedStatus.NEEDS_CREATIVES.ToString())
.ToStatement();
try {
// Get line items by Statement.
LineItemPage page = lineItemService.getLineItemsByStatement(filterStatement);
if (page.results != null && page.results.Length > 0) {
int i = page.startIndex;
foreach (LineItem lineItem in page.results) {
Console.WriteLine("{0}) Line item with ID ='{1}', belonging to order ID = '{2}' and " +
"named '{3}' was found.", i, lineItem.id, lineItem.orderId, lineItem.name);
i++;
}
}
Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
} catch (Exception ex) {
Console.WriteLine("Failed to get line item by Statement. Exception says \"{0}\"",
ex.Message);
}
}