Ejemplo n.º 1
0
    /// <summary>
    /// Retrieves the list of all criteria in an adgroup.
    /// </summary>
    /// <param name="adGroupId">The AdGroup Id.</param>
    /// <param name="customerId">The customer id for the account</param>
    /// <param name="criterionFields">The list of names of criterion fields that
    /// should be saved.</param>
    /// <returns>List of criteria in the adgroup.</returns>
    private AdGroupCriterion[] GetAdGroupCriteria(long adGroupId, long customerId,
        string[] criterionFields) {
      AdGroupCriterionService criterionService = (AdGroupCriterionService) user.GetService(
          AdWordsService.v201109.AdGroupCriterionService, "https://adwords-sandbox.google.com");

      criterionService.RequestHeader.clientCustomerId = customerId.ToString();


      // Create a selector.
      Selector selector = new Selector();
      selector.fields = criterionFields;

      // Restrict the fetch to only the selected AdGroupId.
      Predicate adGroupPredicate = new Predicate();
      adGroupPredicate.field = "AdGroupId";
      adGroupPredicate.@operator = PredicateOperator.EQUALS;
      adGroupPredicate.values = new string[] {adGroupId.ToString()};

      selector.predicates = new Predicate[] {adGroupPredicate};

      selector.paging = new Paging();

      int offset = 0;
      int pageSize = 500;

      AdGroupCriterionPage page = new AdGroupCriterionPage();
      List<AdGroupCriterion> retVal = new List<AdGroupCriterion>();

      do {
        selector.paging.startIndex = offset;
        selector.paging.numberResults = pageSize;

        page = criterionService.get(selector);

        if (page != null && page.entries != null) {
          retVal.AddRange(page.entries);
        }
        offset += pageSize;
      } while (offset < page.totalNumEntries);
      return retVal.ToArray();
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Retrieves the list of all criteria in a campaign.
    /// </summary>
    /// <param name="campaignId">The campaign id.</param>
    /// <param name="customerId">The customer id for the account</param>
    /// <param name="campaignCriterionFields">The list of names of campaign
    /// criterion fields that should be saved.</param>
    /// <returns>List of criteria in the campaign.</returns>
    private CampaignCriterion[] GetCampaignCriteria(long campaignId, long customerId,
        string[] campaignCriterionFields) {
      CampaignCriterionService criterionService = (CampaignCriterionService) user.GetService(
          AdWordsService.v201109.CampaignCriterionService, "https://adwords-sandbox.google.com");

      // Create selector.
      Selector selector = new Selector();
      selector.fields = campaignCriterionFields;

      Predicate predicate = new Predicate();
      predicate.field = "CampaignId";
      predicate.@operator = PredicateOperator.EQUALS;
      predicate.values = new string[] {campaignId.ToString()};

      selector.predicates = new Predicate[] {predicate};

      selector.paging = new Paging();

      int offset = 0;
      int pageSize = 500;

      CampaignCriterionPage page = new CampaignCriterionPage();
      List<CampaignCriterion> retVal = new List<CampaignCriterion>();

      do {
        selector.paging.startIndex = offset;
        selector.paging.numberResults = pageSize;

        // Get all campaign targets.
        page = criterionService.get(selector);
        if (page != null && page.entries != null) {
          retVal.AddRange(page.entries);
        }
        offset += pageSize;
      } while (offset < page.totalNumEntries);
      return retVal.ToArray();
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Retrieves the list of all adgroups in a campaign.
    /// </summary>
    /// <param name="campaignId">Campaign Id.</param>
    /// <param name="customerId">The customer id for the account</param>
    /// <param name="adGroupFields">The list of names of ad group fields that
    /// should be saved.</param>
    /// <param name="adFields">The list of names of ad fields that should be
    /// saved.</param>
    /// <param name="criterionFields">The list of names of criterion fields that
    /// should be saved.</param>
    /// <returns>List of ad groups in the campaign.</returns>
    private LocalAdGroup[] GetAdGroups(long campaignId, long customerId, string[] adGroupFields,
        string[] adFields, string[] criterionFields) {
      List<LocalAdGroup> retVal = new List<LocalAdGroup>();

      AdGroupService adGroupService = (AdGroupService) user.GetService(
          AdWordsService.v201109.AdGroupService, SANDBOX_SERVER);
      adGroupService.RequestHeader.clientCustomerId = customerId.ToString();

      // Create a selector.
      Selector selector = new Selector();
      selector.fields = adGroupFields;

      // Set a filter condition.
      Predicate predicate = new Predicate();
      predicate.field = "CampaignId";
      predicate.@operator = PredicateOperator.EQUALS;
      predicate.values = new string[] {campaignId.ToString()};
      selector.predicates = new Predicate[] {predicate};

      // Set the selector paging.
      selector.paging = new Paging();

      int offset = 0;
      int pageSize = 500;

      AdGroupPage page = new AdGroupPage();

      do {
        selector.paging.startIndex = offset;
        selector.paging.numberResults = pageSize;

        page = adGroupService.get(selector);
        if (page != null && page.entries != null) {
          int i = offset;
          foreach (AdGroup adGroup in page.entries) {
            LocalAdGroup localAdGroup = new LocalAdGroup();

            localAdGroup.AdGroup = adGroup;
            localAdGroup.Ads.AddRange(GetAllAds(adGroup.id, customerId, adFields));
            localAdGroup.Criteria.AddRange(GetAdGroupCriteria(adGroup.id, customerId,
                criterionFields));
            retVal.Add(localAdGroup);
          }
        }
        offset += pageSize;
      } while (offset < page.totalNumEntries);
      return retVal.ToArray();
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Retrieves the list of all ads in an adgroup.
    /// </summary>
    /// <param name="adGroupId">The AdGroup Id.</param>
    /// <param name="customerId">The customer id for the account</param>
    /// <param name="adFields">The list of names of ad fields that should be
    /// saved.</param>
    /// <returns>List of ads in the adgroup.</returns>
    private AdGroupAd[] GetAllAds(long adGroupId, long customerId, string[] adFields) {
      AdGroupAdService adService = (AdGroupAdService) user.GetService(
          AdWordsService.v201109.AdGroupAdService, SANDBOX_SERVER);

      adService.RequestHeader.clientCustomerId = customerId.ToString();

      // Create a selector and set the filters.
      Selector selector = new Selector();

      // Set the fields to select.
      selector.fields = adFields;

      // Restrict the fetch to only the selected AdGroupId.
      Predicate adGroupPredicate = new Predicate();
      adGroupPredicate.field = "AdGroupId";
      adGroupPredicate.@operator = PredicateOperator.EQUALS;
      adGroupPredicate.values = new string[] {adGroupId.ToString()};

      // By default disabled ads aren't returned by the selector. To return
      // them include the DISABLED status in the statuses field.
      Predicate statusPredicate = new Predicate();
      statusPredicate.field = "Status";
      statusPredicate.@operator = PredicateOperator.IN;
      statusPredicate.values = new string[] {AdGroupAdStatus.ENABLED.ToString(),
          AdGroupAdStatus.PAUSED.ToString(), AdGroupAdStatus.DISABLED.ToString()};
      selector.predicates = new Predicate[] {adGroupPredicate, statusPredicate};

      // Select selector paging.
      selector.paging = new Paging();

      int offset = 0;
      int pageSize = 500;

      AdGroupAdPage page = new AdGroupAdPage();
            List<AdGroupAd> retVal = new List<AdGroupAd>();

      do {
        selector.paging.startIndex = offset;
        selector.paging.numberResults = pageSize;

        page = adService.get(selector);

        if (page != null && page.entries != null) {
          int i = offset;

          foreach (AdGroupAd adGroupAd in page.entries) {
            retVal.Add(adGroupAd);
          }
        }
        offset += pageSize;
      } while (offset < page.totalNumEntries);

      return retVal.ToArray();
    }
Ejemplo n.º 5
0
 public virtual MediaPage get(Selector serviceSelector) {
   object[] results = this.Invoke("get", new object[] {serviceSelector});
   return ((MediaPage) (results[0]));
 }
Ejemplo n.º 6
0
    /// <summary>
    /// Retrieves the list of all campaigns in an account.
    /// </summary>
    /// <param name="customerId">The customer id for the account</param>
    /// <param name="campaignFields">The list of names of campaign fields that
    /// should be saved.</param>
    /// <param name="adGroupFields">The list of names of ad group fields that
    /// should be saved.</param>
    /// <param name="adFields">The list of names of ad fields that should be
    /// saved.</param>
    /// <param name="criterionFields">The list of names of criterion fields that
    /// should be saved.</param>
    /// <param name="campaignCriterionFields">The list of names of campaign
    /// criterion fields that should be saved.</param>
    /// <returns>List of campaigns in the account.</returns>
    private LocalCampaign[] GetAccountCampaigns(long customerId, string[] campaignFields,
        string[] adGroupFields, string[] adFields, string[] criterionFields,
        string[] campaignCriterionFields) {
      List<LocalCampaign> retVal = new List<LocalCampaign>();

      CampaignService campaignService = (CampaignService) user.GetService(
          AdWordsService.v201109.CampaignService, SANDBOX_SERVER);
      campaignService.RequestHeader.clientCustomerId = customerId.ToString();

      // Create a selector.
      Selector selector = new Selector();
      selector.fields = campaignFields;

      selector.paging = new Paging();

      int offset = 0;
      int pageSize = 500;

      CampaignPage page = new CampaignPage();

      do {
        selector.paging.startIndex = offset;
        selector.paging.numberResults = pageSize;

        page = campaignService.get(selector);
        if (page != null && page.entries != null) {
          int i = offset;
          foreach (Campaign campaign in page.entries) {
            LocalCampaign localCampaign = new LocalCampaign();
            localCampaign.Campaign = campaign;
            localCampaign.AdGroups.AddRange(GetAdGroups(campaign.id, customerId, adGroupFields,
                adFields, criterionFields));
            localCampaign.CampaignCriteria.AddRange(GetCampaignCriteria(campaign.id, customerId,
                campaignCriterionFields));
            retVal.Add(localCampaign);
          }
        }
        offset += pageSize;
      } while (offset < page.totalNumEntries);

      return retVal.ToArray();
    }
Ejemplo n.º 7
0
 public virtual LocationCriterion[] get(Selector selector) {
   object[] results = this.Invoke("get", new object[] {selector});
   return ((LocationCriterion[]) (results[0]));
 }
Ejemplo n.º 8
0
 public virtual CriterionBidLandscapePage getCriterionBidLandscape(Selector serviceSelector) {
   object[] results = this.Invoke("getCriterionBidLandscape", new object[] {serviceSelector});
   return ((CriterionBidLandscapePage) (results[0]));
 }
Ejemplo n.º 9
0
 public virtual AdGroupBidLandscapePage getAdGroupBidLandscape(Selector serviceSelector) {
   object[] results = this.Invoke("getAdGroupBidLandscape", new object[] {serviceSelector});
   return ((AdGroupBidLandscapePage) (results[0]));
 }
Ejemplo n.º 10
0
 public virtual CampaignCriterionPage get(Selector serviceSelector) {
   object[] results = this.Invoke("get", new object[] {serviceSelector});
   return ((CampaignCriterionPage) (results[0]));
 }
Ejemplo n.º 11
0
 public virtual ConversionTrackerPage get(Selector serviceSelector) {
   object[] results = this.Invoke("get", new object[] {serviceSelector});
   return ((ConversionTrackerPage) (results[0]));
 }