本文整理汇总了C#中Google.Api.Ads.AdWords.Lib.AdWordsUser.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# AdWordsUser.GetService方法的具体用法?C# AdWordsUser.GetService怎么用?C# AdWordsUser.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google.Api.Ads.AdWords.Lib.AdWordsUser
的用法示例。
在下文中一共展示了AdWordsUser.GetService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="businessId">The AdWords Express business id.</param>
/// <param name="promotionId">The promotion id.</param>
public void Run(AdWordsUser user, long businessId, long promotionId) {
// Get the ExpressBusinessService.
ExpressBusinessService businessService = (ExpressBusinessService)
user.GetService(AdWordsService.v201509.ExpressBusinessService);
// Get the PromotionService
PromotionService promotionService = (PromotionService)
user.GetService(AdWordsService.v201509.PromotionService);
// Set the business ID to the service.
promotionService.RequestHeader.expressBusinessId = businessId;
// Update the budget for the promotion
Promotion promotion = new Promotion();
promotion.id = promotionId;
Money newBudget = new Money();
newBudget.microAmount = 2000000;
promotion.budget = newBudget;
PromotionOperation operation = new PromotionOperation();
[email protected] = Operator.SET;
operation.operand = promotion;
try {
Promotion[] updatedPromotions = promotionService.mutate(
new PromotionOperation[] { operation });
Console.WriteLine("Promotion ID {0} for business ID {1} now has budget micro " +
"amount {2}.", promotionId, businessId,
updatedPromotions[0].budget.microAmount);
} catch (Exception e) {
throw new System.ApplicationException("Failed to update promotions.", e);
}
}
示例2: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="budgetId">The budget id.</param>
/// <param name="merchantId">The Merchant Center account id.</param>
public void Run(AdWordsUser user, long budgetId, long merchantId)
{
// Get the required services.
CampaignService campaignService = (CampaignService) user.GetService(
AdWordsService.v201502.CampaignService);
AdGroupService adGroupService = (AdGroupService) user.GetService(
AdWordsService.v201502.AdGroupService);
AdGroupAdService adGroupAdService = (AdGroupAdService) user.GetService(
AdWordsService.v201502.AdGroupAdService);
try {
Campaign campaign = CreateCampaign(budgetId, merchantId, campaignService);
Console.WriteLine("Campaign with name '{0}' and ID '{1}' was added.", campaign.name,
campaign.id);
AdGroup adGroup = CreateAdGroup(adGroupService, campaign);
Console.WriteLine("Ad group with name '{0}' and ID '{1}' was added.", adGroup.name,
adGroup.id);
AdGroupAd adGroupAd = CreateProductAd(adGroupAdService, adGroup);
Console.WriteLine("Product ad with ID {0}' was added.", adGroupAd.ad.id);
} catch (Exception e) {
throw new System.ApplicationException("Failed to create shopping campaign.", e);
}
}
示例3: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="campaignId">The campaign ID.</param>
public void Run(AdWordsUser user, long campaignId) {
// Get the VideoCampaignCriterionService.
VideoCampaignCriterionService service =
(VideoCampaignCriterionService) user.GetService(
AdWordsService.v201406.VideoCampaignCriterionService);
try {
VideoCampaignCriterion criterion = new VideoCampaignCriterion();
criterion.campaignId = campaignId;
// for a list of languages, see
// https://devsite.googleplex.com/adwords/api/docs/appendix/languagecodes
LanguageVideoCriterion englishCriterion = new LanguageVideoCriterion();
englishCriterion.id = 1001L;
criterion.criterion = englishCriterion;
VideoCampaignCriterionOperation operation = new VideoCampaignCriterionOperation();
operation.operand = criterion;
[email protected] = Operator.ADD;
VideoCampaignCriterionReturnValue retval = service.mutate(
new VideoCampaignCriterionOperation[] { operation });
if (retval != null && retval.value != null && retval.value.Length > 0) {
VideoCampaignCriterion newCriterion = retval.value[0];
Console.WriteLine("Video campaign criterion with id = {0} and type = {1} was added " +
"to campaign id {2}", newCriterion.criterion.id,
newCriterion.criterion.BaseCriterionType, newCriterion.campaignId);
} else {
Console.WriteLine("No video campaign criteria were added.");
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to add video campaign criteria.", ex);
}
}
示例4: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="businessId">The AdWords Express business id.</param>
public void Run(AdWordsUser user, long businessId) {
// Get the ExpressBusinessService.
ExpressBusinessService businessService = (ExpressBusinessService)
user.GetService(AdWordsService.v201406.ExpressBusinessService);
// Update the website and address for the business
ExpressBusiness business = new ExpressBusiness();
business.id = businessId;
business.name = "Express Interplanetary Cruise #" + ExampleUtilities.GetShortRandomString();
business.website = "http://www.example.com/?myParam=" + businessId;
ExpressBusinessOperation operation = new ExpressBusinessOperation();
[email protected] = Operator.SET;
operation.operand = business;
try {
ExpressBusiness[] updatedBusinesses =
businessService.mutate(new ExpressBusinessOperation[] { operation });
Console.WriteLine("Express business with ID {0} and name '{1}' was updated.",
updatedBusinesses[0].id, updatedBusinesses[0].name);
} catch (Exception ex) {
throw new System.ApplicationException("Failed to update express business.", ex);
}
}
示例5: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="adGroupId">Id of the ad group to which keywords are added.
/// </param>
public void Run(AdWordsUser user, long adGroupId) {
// Get the AdGroupCriterionService.
AdGroupCriterionService adGroupCriterionService =
(AdGroupCriterionService) user.GetService(
AdWordsService.v201509.AdGroupCriterionService);
List<AdGroupCriterionOperation> operations = new List<AdGroupCriterionOperation>();
foreach (string keywordText in KEYWORDS) {
// Create the keyword.
Keyword keyword = new Keyword();
keyword.text = keywordText;
keyword.matchType = KeywordMatchType.BROAD;
// Create the biddable ad group criterion.
BiddableAdGroupCriterion keywordCriterion = new BiddableAdGroupCriterion();
keywordCriterion.adGroupId = adGroupId;
keywordCriterion.criterion = keyword;
// Optional: Set the user status.
keywordCriterion.userStatus = UserStatus.PAUSED;
// Optional: Set the keyword destination url.
keywordCriterion.finalUrls = new UrlList() {
urls = new string[] { "http://example.com/mars/cruise/?kw=" +
HttpUtility.UrlEncode(keywordText) }
};
// Create the operations.
AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
[email protected] = Operator.ADD;
operation.operand = keywordCriterion;
operations.Add(operation);
}
try {
// Create the keywords.
AdGroupCriterionReturnValue retVal = adGroupCriterionService.mutate(operations.ToArray());
// Display the results.
if (retVal != null && retVal.value != null) {
foreach (AdGroupCriterion adGroupCriterion in retVal.value) {
// If you are adding multiple type of criteria, then you may need to
// check for
//
// if (adGroupCriterion is Keyword) { ... }
//
// to identify the criterion type.
Console.WriteLine("Keyword with ad group id = '{0}', keyword id = '{1}', text = " +
"'{2}' and match type = '{3}' was created.", adGroupCriterion.adGroupId,
adGroupCriterion.criterion.id, (adGroupCriterion.criterion as Keyword).text,
(adGroupCriterion.criterion as Keyword).matchType);
}
} else {
Console.WriteLine("No keywords were added.");
}
} catch (Exception e) {
throw new System.ApplicationException("Failed to create keywords.", e);
}
}
示例6: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="adGroupId">Id of the ad group to be updated.</param>
public void Run(AdWordsUser user, long adGroupId) {
// Get the AdGroupService.
AdGroupService adGroupService =
(AdGroupService) user.GetService(AdWordsService.v201402.AdGroupService);
// Create the ad group.
AdGroup adGroup = new AdGroup();
adGroup.status = AdGroupStatus.PAUSED;
adGroup.id = adGroupId;
// Create the operation.
AdGroupOperation operation = new AdGroupOperation();
[email protected] = Operator.SET;
operation.operand = adGroup;
try {
// Update the ad group.
AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[] {operation});
// Display the results.
if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
AdGroup pausedAdGroup = retVal.value[0];
Console.WriteLine("Ad group with id = '{0}' was successfully updated.",
pausedAdGroup.id);
} else {
Console.WriteLine("No ad groups were updated.");
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to update ad group.", ex);
}
}
示例7: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="campaignId">Id of the campaign to be removed.</param>
public void Run(AdWordsUser user, long campaignId) {
// Get the CampaignService.
CampaignService campaignService = (CampaignService) user.GetService(
AdWordsService.v201406.CampaignService);
// Create campaign with REMOVED status.
Campaign campaign = new Campaign();
campaign.id = campaignId;
// When removing a campaign, rename it to avoid name collisions with new
// campaigns.
campaign.name = "Removed Campaign - " + ExampleUtilities.GetRandomString();
campaign.status = CampaignStatus.REMOVED;
// Create the operation.
CampaignOperation operation = new CampaignOperation();
operation.operand = campaign;
[email protected] = Operator.SET;
try {
// Remove the campaign.
CampaignReturnValue retVal = campaignService.mutate(new CampaignOperation[] {operation});
// Display the results.
if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
Campaign removedCampaign = retVal.value[0];
Console.WriteLine("Campaign with id = \"{0}\" was renamed to \"{1}\" and removed.",
removedCampaign.id, removedCampaign.name);
} else {
Console.WriteLine("No campaigns were removed.");
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to remove campaign.", ex);
}
}
示例8: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="adGroupId">Id of the ad group to be removed.</param>
public void Run(AdWordsUser user, long adGroupId) {
// Get the AdGroupService.
AdGroupService adGroupService = (AdGroupService) user.GetService(
AdWordsService.v201506.AdGroupService);
// Create ad group with REMOVED status.
AdGroup adGroup = new AdGroup();
adGroup.id = adGroupId;
adGroup.status = AdGroupStatus.REMOVED;
// Create the operation.
AdGroupOperation operation = new AdGroupOperation();
operation.operand = adGroup;
[email protected] = Operator.SET;
try {
// Remove the ad group.
AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[] {operation});
// Display the results.
if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
AdGroup removedAdGroup = retVal.value[0];
Console.WriteLine("Ad group with id = \"{0}\" and name = \"{1}\" was removed.",
removedAdGroup.id, removedAdGroup.name);
} else {
Console.WriteLine("No ad groups were removed.");
}
} catch (Exception e) {
throw new System.ApplicationException("Failed to remove ad group.", e);
}
}
示例9: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
public void Run(AdWordsUser user)
{
// Get the MediaService.
MediaService mediaService = (MediaService) user.GetService(
AdWordsService.v201502.MediaService);
// Create a selector.
Selector selector = new Selector();
selector.fields = new string[] {"MediaId", "Width", "Height", "MimeType"};
// Set the filter.
Predicate predicate = new Predicate();
[email protected] = PredicateOperator.IN;
predicate.field = "Type";
predicate.values = new string[] {MediaMediaType.VIDEO.ToString(),
MediaMediaType.IMAGE.ToString()};
selector.predicates = new Predicate[] {predicate};
// Set selector paging.
selector.paging = new Paging();
int offset = 0;
int pageSize = 500;
MediaPage page = new MediaPage();
try {
do {
selector.paging.startIndex = offset;
selector.paging.numberResults = pageSize;
page = mediaService.get(selector);
if (page != null && page.entries != null) {
int i = offset;
foreach (Media media in page.entries) {
if (media is Video) {
Video video = (Video) media;
Console.WriteLine("{0}) Video with id \"{1}\" and name \"{2}\" was found.",
i, video.mediaId, video.name);
} else if (media is Image) {
Image image = (Image) media;
Dictionary<MediaSize, Dimensions> dimensions =
CreateMediaDimensionMap(image.dimensions);
Console.WriteLine("{0}) Image with id '{1}', dimensions '{2}x{3}', and MIME type " +
"'{4}' was found.", i, image.mediaId, dimensions[MediaSize.FULL].width,
dimensions[MediaSize.FULL].height, image.mimeType);
}
i++;
}
}
offset += pageSize;
} while (offset < page.totalNumEntries);
Console.WriteLine("Number of images and videos found: {0}", page.totalNumEntries);
} catch (Exception e) {
throw new System.ApplicationException("Failed to get images and videos.", e);
}
}
示例10: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
public void Run(AdWordsUser user) {
// Get the MediaService.
MediaService mediaService = (MediaService) user.GetService(
AdWordsService.v201509.MediaService);
try {
// Create HTML5 media.
byte[] html5Zip = MediaUtilities.GetAssetDataFromUrl("https://goo.gl/9Y7qI2");
// Create a media bundle containing the zip file with all the HTML5 components.
Media[] mediaBundle = new Media[] {
new MediaBundle() {
data = html5Zip,
type = MediaMediaType.MEDIA_BUNDLE
}};
// Upload HTML5 zip.
mediaBundle = mediaService.upload(mediaBundle);
// Display HTML5 zip.
if (mediaBundle != null && mediaBundle.Length > 0) {
Media newBundle = mediaBundle[0];
Dictionary<MediaSize, Dimensions> dimensions =
CreateMediaDimensionMap(newBundle.dimensions);
Console.WriteLine("HTML5 media with id \"{0}\", dimensions \"{1}x{2}\", and MIME type " +
"\"{3}\" was uploaded.", newBundle.mediaId, dimensions[MediaSize.FULL].width,
dimensions[MediaSize.FULL].height, newBundle.mimeType
);
} else {
Console.WriteLine("No HTML5 zip was uploaded.");
}
} catch (Exception e) {
throw new System.ApplicationException("Failed to upload HTML5 zip file.", e);
}
}
示例11: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="campaignId">Id of the campaign to be deleted.</param>
public void Run(AdWordsUser user, long campaignId) {
// Get the CampaignService.
CampaignService campaignService = (CampaignService) user.GetService(
AdWordsService.v201402.CampaignService);
// Create campaign with DELETED status.
Campaign campaign = new Campaign();
campaign.id = campaignId;
campaign.status = CampaignStatus.DELETED;
// Create the operation.
CampaignOperation operation = new CampaignOperation();
operation.operand = campaign;
[email protected] = Operator.SET;
try {
// Delete the campaign.
CampaignReturnValue retVal = campaignService.mutate(new CampaignOperation[] {operation});
// Display the results.
if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
Campaign deletedCampaign = retVal.value[0];
Console.WriteLine("Campaign with id = \"{0}\" was renamed to \"{1}\" and deleted.",
deletedCampaign.id, deletedCampaign.name);
} else {
Console.WriteLine("No campaigns were deleted.");
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to delete campaign.", ex);
}
}
示例12: CreateCustomizerFeed
/// <summary>
/// Creates a new Feed for ad customizers.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="feedName">Name of the feed to be created.</param>
/// <returns>A new Ad customizer feed.</returns>
private static AdCustomizerFeed CreateCustomizerFeed(AdWordsUser user, string feedName) {
AdCustomizerFeedService adCustomizerFeedService = (AdCustomizerFeedService) user.GetService(
AdWordsService.v201509.AdCustomizerFeedService);
AdCustomizerFeed feed = new AdCustomizerFeed() {
feedName = feedName,
feedAttributes = new AdCustomizerFeedAttribute[] {
new AdCustomizerFeedAttribute() {
name = "Name",
type = AdCustomizerFeedAttributeType.STRING
},
new AdCustomizerFeedAttribute() {
name = "Price",
type = AdCustomizerFeedAttributeType.PRICE
},
new AdCustomizerFeedAttribute() {
name = "Date",
type = AdCustomizerFeedAttributeType.DATE_TIME
},
}
};
AdCustomizerFeedOperation feedOperation = new AdCustomizerFeedOperation();
feedOperation.operand = feed;
[email protected] = (Operator.ADD);
AdCustomizerFeed addedFeed = adCustomizerFeedService.mutate(
new AdCustomizerFeedOperation[] { feedOperation }).value[0];
Console.WriteLine("Created ad customizer feed with ID = {0} and name = '{1}'.",
addedFeed.feedId, addedFeed.feedName);
return addedFeed;
}
示例13: GetMethodQuotaUsage
/// <summary>
/// Gets the quota usage of an account in units, broken down by
/// method name.
/// </summary>
/// <param name="user">The AdWordsUser object for which the quota usage
/// should be retrieved.</param>
/// <param name="startDate">Start date for the date range for which
/// results are to be retrieved.</param>
/// <param name="endDate">End date for the date range for which results
/// are to be retrieved.</param>
/// <returns>A list of MethodQuotaUsage objects, with one entry for each
/// method.</returns>
public static List<MethodQuotaUsage> GetMethodQuotaUsage(AdWordsUser user, DateTime startDate,
DateTime endDate) {
List<MethodQuotaUsage> methodQuotaUsageList = new List<MethodQuotaUsage>();
SortedList<string, List<string>> serviceToMethodsMap = GetAllMethods();
InfoService service = (InfoService) user.GetService(AdWordsService.v201109.InfoService);
foreach (string serviceName in serviceToMethodsMap.Keys) {
List<string> methods = serviceToMethodsMap[serviceName];
foreach (string methodName in methods) {
InfoSelector selector = new InfoSelector();
selector.apiUsageTypeSpecified = true;
selector.apiUsageType = ApiUsageType.UNIT_COUNT;
selector.dateRange = new DateRange();
selector.dateRange.min = startDate.ToString("YYYYMMDD");
selector.dateRange.max = endDate.ToString("YYYYMMDD");
selector.serviceName = serviceName;
if (methodName.Contains(".")) {
string[] splits = methodName.Split('.');
selector.methodName = splits[0];
selector.operatorSpecified = true;
[email protected] = (Operator) Enum.Parse(typeof(Operator), splits[1]);
} else {
selector.methodName = methodName;
}
methodQuotaUsageList.Add(new MethodQuotaUsage(serviceName, methodName,
service.get(selector).cost));
}
}
return methodQuotaUsageList;
}
示例14: AddCampaignTargetingCriteria
/// <summary>
/// Adds the campaign targeting criteria to a campaign.
/// </summary>
/// <param name="user">The user.</param>
/// <param name="campaignId">The campaign id.</param>
/// <returns>The campaign criteria id.</returns>
public long AddCampaignTargetingCriteria(AdWordsUser user, long campaignId)
{
// Get the CampaignCriterionService.
CampaignCriterionService campaignCriterionService =
(CampaignCriterionService) user.GetService(
AdWordsService.v201309.CampaignCriterionService);
// Create language criteria.
// See http://code.google.com/apis/adwords/docs/appendix/languagecodes.html
// for a detailed list of language codes.
Language language1 = new Language();
language1.id = 1002; // French
CampaignCriterion languageCriterion1 = new CampaignCriterion();
languageCriterion1.campaignId = campaignId;
languageCriterion1.criterion = language1;
CampaignCriterion[] criteria = new CampaignCriterion[] {languageCriterion1};
List<CampaignCriterionOperation> operations = new List<CampaignCriterionOperation>();
foreach (CampaignCriterion criterion in criteria) {
CampaignCriterionOperation operation = new CampaignCriterionOperation();
[email protected] = Operator.ADD;
operation.operand = criterion;
operations.Add(operation);
}
CampaignCriterionReturnValue retVal = campaignCriterionService.mutate(operations.ToArray());
return retVal.value[0].criterion.id;
}
示例15: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="queryString">The video search query text.</param>
public void Run(AdWordsUser user, string queryString) {
// Get the VideoService.
VideoService videoService = (VideoService) user.GetService(
AdWordsService.v201406.VideoService);
// Create a selector.
VideoSearchSelector selector = new VideoSearchSelector();
selector.searchType = VideoSearchSelectorSearchType.VIDEO;
selector.query = queryString;
selector.paging = new Paging();
selector.paging.startIndex = 0;
selector.paging.numberResults = PAGE_SIZE;
try {
// Run the query.
VideoSearchPage page = videoService.search(selector);
// Display videos.
if (page != null && page.totalNumEntries > 0) {
foreach (YouTubeVideo video in page.entries) {
Console.WriteLine("YouTube video ID {0} with title {1} found.", video.id, video.title);
}
Console.WriteLine("Total number of matching videos: {0}.", page.totalNumEntries);
} else {
Console.WriteLine("No videos matching {0} were found.", queryString);
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to search for videos.", ex);
}
}