Exemplo n.º 1
0
    /// <summary>
    /// Gets the ad group ad by ID.
    /// </summary>
    /// <param name="adGroupAdService">The AdGroupAdService instance.</param>
    /// <param name="adGroupId">ID of the ad group.</param>
    /// <param name="adId">ID of the ad to be retrieved.</param>
    /// <returns>The AdGroupAd if the item could be retrieved, null otherwise.
    /// </returns>
    private AdGroupAd GetAdGroupAd(AdGroupAdService adGroupAdService, long adGroupId, long adId) {
      // Create a selector.
      Selector selector = new Selector();
      selector.fields = new string[] { "Id", "Url" };

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

      Predicate adPredicate = new Predicate();
      adPredicate.field = "Id";
      adPredicate.@operator = PredicateOperator.EQUALS;
      adPredicate.values = new string[] { adId.ToString() };

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

      // Get the ad.
      AdGroupAdPage page = adGroupAdService.get(selector);

      if (page != null && page.entries != null && page.entries.Length > 0) {
        return page.entries[0];
      } else {
        return null;
      }
    }
        /// <summary>
        /// Gets the ad group ad by ID.
        /// </summary>
        /// <param name="adGroupAdService">The AdGroupAdService instance.</param>
        /// <param name="adGroupId">ID of the ad group.</param>
        /// <param name="adId">ID of the ad to be retrieved.</param>
        /// <returns>The AdGroupAd if the item could be retrieved, null otherwise.
        /// </returns>
        private AdGroupAd GetAdGroupAd(AdGroupAdService adGroupAdService, long adGroupId, long adId)
        {
            // Create a selector.
              Selector selector = new Selector() {
            fields = new string[] { Ad.Fields.Id, Ad.Fields.Url },
            predicates = new Predicate[] {
              // Restrict the fetch to only the selected ad group ID and ad ID.
              Predicate.Equals(AdGroupAd.Fields.AdGroupId, adGroupId),
              Predicate.Equals(Ad.Fields.Id, adId)
            }
              };

              // Get the ad.
              AdGroupAdPage page = adGroupAdService.get(selector);

              if (page != null && page.entries != null && page.entries.Length > 0) {
            return page.entries[0];
              } else {
            return null;
              }
        }