本文整理汇总了C#中Google.Api.Ads.AdWords.Lib.AdWordsUser类的典型用法代码示例。如果您正苦于以下问题:C# AdWordsUser类的具体用法?C# AdWordsUser怎么用?C# AdWordsUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AdWordsUser类属于Google.Api.Ads.AdWords.Lib命名空间,在下文中一共展示了AdWordsUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="reportType">The report type to be run.</param>
public void Run(AdWordsUser user, ReportDefinitionReportType reportType) {
// Get the ReportDefinitionService.
ReportDefinitionService reportDefinitionService = (ReportDefinitionService) user.GetService(
AdWordsService.v201509.ReportDefinitionService);
try {
// Get the report fields.
ReportDefinitionField[] reportDefinitionFields = reportDefinitionService.getReportFields(
reportType);
if (reportDefinitionFields != null && reportDefinitionFields.Length > 0) {
// Display report fields.
Console.WriteLine("The report type '{0}' contains the following fields:", reportType);
foreach (ReportDefinitionField reportDefinitionField in reportDefinitionFields) {
Console.Write("- {0} ({1})", reportDefinitionField.fieldName,
reportDefinitionField.fieldType);
if (reportDefinitionField.enumValues != null) {
Console.Write(" := [{0}]", String.Join(", ", reportDefinitionField.enumValues));
}
Console.WriteLine();
}
} else {
Console.WriteLine("This report type has no fields.");
}
} catch (Exception e) {
throw new System.ApplicationException("Failed to retrieve fields for report type.", e);
}
}
示例3: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="campaignId">Id of the campaign to which keywords are added.</param>
public void Run(AdWordsUser user, long campaignId) {
try {
// Create a shared set.
SharedSet sharedSet = CreateSharedKeywordSet(user);
Console.WriteLine("Shared set with id = {0}, name = {1}, type = {2}, status = {3} " +
"was created.", sharedSet.sharedSetId, sharedSet.name, sharedSet.type,
sharedSet.status);
// Add new keywords to the shared set.
string[] keywordTexts = new string[] {"mars cruise", "mars hotels"};
SharedCriterion[] sharedCriteria = AddKeywordsToSharedSet(user, sharedSet.sharedSetId,
keywordTexts);
foreach (SharedCriterion sharedCriterion in sharedCriteria) {
Keyword keyword = sharedCriterion.criterion as Keyword;
Console.WriteLine("Added keyword with id = {0}, text = {1}, matchtype = {2} to " +
"shared set with id = {3}.", keyword.id, keyword.text, keyword.matchType,
sharedSet.sharedSetId);
}
// Attach the shared set to the campaign.
CampaignSharedSet attachedSharedSet = AttachSharedSetToCampaign(user, campaignId,
sharedSet.sharedSetId);
Console.WriteLine("Attached shared set with id = {0} to campaign id {1}.",
attachedSharedSet.sharedSetId, attachedSharedSet.campaignId);
} catch (Exception ex) {
throw new System.ApplicationException("Failed to create shared keyword set and attach " +
"it to a campaign.", ex);
}
}
示例4: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="fileName">The file to which the report is downloaded.
/// </param>
public void Run(AdWordsUser user, string fileName)
{
string query = "SELECT CampaignId, AdGroupId, Id, Criteria, CriteriaType, Impressions, " +
"Clicks, Cost FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN [ACTIVE, PAUSED] " +
"DURING LAST_7_DAYS";
string filePath = ExampleUtilities.GetHomeDir() + Path.DirectorySeparatorChar + fileName;
try {
// If you know that your report is small enough to fit in memory, then
// you can instead use
// ReportUtilities utilities = new ReportUtilities(user);
// utilities.ReportVersion = "v201306";
// ClientReport report = utilities.GetClientReport(query, format);
//
// // Get the text report directly if you requested a text format
// // (e.g. xml)
// string reportText = report.Text;
//
// // Get the binary report if you requested a binary format
// // (e.g. gzip)
// byte[] reportBytes = report.Contents;
//
// // Deflate a zipped binary report for further processing.
// string deflatedReportText = Encoding.UTF8.GetString(
// MediaUtilities.DeflateGZipData(report.Contents));
ReportUtilities utilities = new ReportUtilities(user);
utilities.ReportVersion = "v201306";
utilities.DownloadClientReport(query, DownloadFormat.GZIPPED_CSV.ToString(), filePath);
Console.WriteLine("Report was downloaded to '{0}'.", filePath);
} catch (Exception ex) {
throw new System.ApplicationException("Failed to download report.", ex);
}
}
示例5: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
public void Run(AdWordsUser user)
{
// Get the ManagedCustomerService.
ManagedCustomerService managedCustomerService = (ManagedCustomerService) user.GetService(
AdWordsService.v201306.ManagedCustomerService);
managedCustomerService.RequestHeader.clientCustomerId = null;
// Create selector.
Selector selector = new Selector();
selector.fields = new String[] {"Login", "CustomerId", "Name"};
try {
// Get results.
ManagedCustomerPage page = managedCustomerService.get(selector);
// Display serviced account graph.
if (page.entries != null) {
// Create map from customerId to customer node.
Dictionary<long, ManagedCustomerTreeNode> customerIdToCustomerNode =
new Dictionary<long, ManagedCustomerTreeNode>();
// Create account tree nodes for each customer.
foreach (ManagedCustomer customer in page.entries) {
ManagedCustomerTreeNode node = new ManagedCustomerTreeNode();
node.Account = customer;
customerIdToCustomerNode.Add(customer.customerId, node);
}
// For each link, connect nodes in tree.
if (page.links != null) {
foreach (ManagedCustomerLink link in page.links) {
ManagedCustomerTreeNode managerNode =
customerIdToCustomerNode[link.managerCustomerId];
ManagedCustomerTreeNode childNode = customerIdToCustomerNode[link.clientCustomerId];
childNode.ParentNode = managerNode;
if (managerNode != null) {
managerNode.ChildAccounts.Add(childNode);
}
}
}
// Find the root account node in the tree.
ManagedCustomerTreeNode rootNode = null;
foreach (ManagedCustomer account in page.entries) {
if (customerIdToCustomerNode[account.customerId].ParentNode == null) {
rootNode = customerIdToCustomerNode[account.customerId];
break;
}
}
// Display account tree.
Console.WriteLine("Login, CustomerId, Name");
Console.WriteLine(rootNode.ToTreeString(0, new StringBuilder()));
} else {
Console.WriteLine("No serviced accounts were found.");
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to create ad groups.", ex);
}
}
示例6: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="adGroupId">ID of the ad group that contains the ad.</param>
/// <param name="adId">ID of the ad to be upgraded.</param>
public void Run(AdWordsUser user, long adGroupId, long adId) {
// Get the AdGroupAdService.
AdGroupAdService adGroupAdService = (AdGroupAdService)
user.GetService(AdWordsService.v201502.AdGroupAdService);
try {
// Retrieve the Ad.
AdGroupAd adGroupAd = GetAdGroupAd(adGroupAdService, adGroupId, adId);
if (adGroupAd == null) {
Console.WriteLine("Ad not found.");
return;
}
// Copy the destination url to the final url.
AdUrlUpgrade upgradeUrl = new AdUrlUpgrade();
upgradeUrl.adId = adGroupAd.ad.id;
upgradeUrl.finalUrl = adGroupAd.ad.url;
// Upgrade the ad.
Ad[] upgradedAds = adGroupAdService.upgradeUrl(new AdUrlUpgrade[] { upgradeUrl });
// Display the results.
if (upgradedAds != null && upgradedAds.Length > 0) {
foreach (Ad upgradedAd in upgradedAds) {
Console.WriteLine("Ad with id = {0} and destination url = {1} was upgraded.",
upgradedAd.id, upgradedAd.finalUrls[0]);
}
} else {
Console.WriteLine("No ads were upgraded.");
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to upgrade ads.", ex);
}
}
示例7: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="fileName">The file to which the report is downloaded.
/// </param>
public void Run(AdWordsUser user, string fileName)
{
ReportDefinition definition = new ReportDefinition() {
reportName = "Last 7 days CRITERIA_PERFORMANCE_REPORT",
reportType = ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT,
downloadFormat = DownloadFormat.GZIPPED_CSV,
dateRangeType = ReportDefinitionDateRangeType.LAST_7_DAYS,
selector = new Selector() {
fields = new string[] {"CampaignId", "AdGroupId", "Id", "CriteriaType", "Criteria",
"FinalUrls", "Clicks", "Impressions", "Cost"},
predicates = new Predicate[] {
Predicate.In("Status", new string[] {"ENABLED", "PAUSED"})
}
},
// Optional: Include zero impression rows.
includeZeroImpressions = true
};
string filePath = ExampleUtilities.GetHomeDir() + Path.DirectorySeparatorChar + fileName;
try {
ReportUtilities utilities = new ReportUtilities(user, "v201502", definition);
using (ReportResponse response = utilities.GetResponse()) {
response.Save(filePath);
}
Console.WriteLine("Report was downloaded to '{0}'.", filePath);
} catch (Exception e) {
throw new System.ApplicationException("Failed to download report.", e);
}
}
示例8: 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);
}
}
示例9: Main
/// <summary>
/// Main method, to run this code example as a standalone application.
/// </summary>
/// <param name="args">The command line arguments.</param>
public static void Main(string[] args) {
AddGoogleMyBusinessLocationExtensions codeExample =
new AddGoogleMyBusinessLocationExtensions();
Console.WriteLine(codeExample.Description);
AdWordsUser user = new AdWordsUser();
try {
// The email address of either an owner or a manager of the GMB account.
string gmbEmailAddress = "INSERT_GMB_EMAIL_ADDRESS_HERE";
// Refresh the access token so that there's a valid access token.
user.OAuthProvider.RefreshAccessToken();
// If the gmbEmailAddress above is the same user you used to generate
// your AdWords API refresh token, leave the assignment below unchanged.
// Otherwise, to obtain an access token for your GMB account, run the
// OAuth Token generator utility while logged in as the same user as
// gmbEmailAddress. Copy and paste the AccessToken value into the
// assignment below.
string gmbAccessToken = user.OAuthProvider.AccessToken;
// If the gmbEmailAddress above is for a GMB manager instead of the GMB
// account owner, then set businessAccountIdentifier to the +Page ID of
// a location for which the manager has access. See the location
// extensions guide at
// https://developers.google.com/adwords/api/docs/guides/feed-services-locations
// for details.
String businessAccountIdentifier = null;
codeExample.Run(user, gmbEmailAddress, gmbAccessToken, businessAccountIdentifier);
} catch (Exception e) {
Console.WriteLine("An exception occurred while running this code example. {0}",
ExampleUtilities.FormatException(e));
}
}
示例10: 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);
}
}
示例11: 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);
}
}
示例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="campaignId">The campaign ID.</param>
/// <param name="videoId">The Youtube video ID.</param>
public void Run(AdWordsUser user, long campaignId, string videoId) {
// Get the VideoTargetingGroupService.
VideoTargetingGroupService videoTargetingGroupService =
(VideoTargetingGroupService) user.GetService(
AdWordsService.v201406.VideoTargetingGroupService);
TargetingGroup targetingGroup = new TargetingGroup();
targetingGroup.campaignId = campaignId;
targetingGroup.name = "My Targeting Group " + ExampleUtilities.GetRandomString();
try {
TargetingGroupOperation operation = new TargetingGroupOperation();
operation.operand = targetingGroup;
[email protected] = Operator.ADD;
TargetingGroupReturnValue retval = videoTargetingGroupService.mutate(
new TargetingGroupOperation[] { operation });
if (retval != null && retval.value != null && retval.value.Length > 0) {
TargetingGroup newTargetingGroup = retval.value[0];
Console.WriteLine("New targeting group with id = {0}, name = {1} was created in " +
"campaign id {2}", newTargetingGroup.id, newTargetingGroup.name,
newTargetingGroup.campaignId);
} else {
Console.WriteLine("No targeting group was created.");
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to create targeting group.", ex);
}
}