Exemplo n.º 1
0
        protected override void PopulateAdManager()
        {
            base.PopulateAdManager();

            // Register 1 BigBox ad
            AdUnits.Add(AdManagerModel.Register(AdType.BigBox));
        }
        /// <summary>This example prints all ad units in a publisher ad client.</summary>
        /// <param name="accountId">The ID for the publisher account to be used.</param>
        /// <param name="adClientId">An arbitrary publisher ad client ID.</param>
        private void GetAllAdUnits(string accountId, string adClientId)
        {
            Console.WriteLine("=================================================================");
            Console.WriteLine("Listing all ad units for ad client {0}", adClientId);
            Console.WriteLine("=================================================================");

            // Retrieve ad client list in pages and display data as we receive it.
            string  pageToken      = null;
            AdUnits adUnitResponse = null;

            do
            {
                var adUnitRequest = this.service.Accounts.Adunits.List(accountId, adClientId);
                adUnitRequest.MaxResults = this.maxListPageSize;
                adUnitRequest.PageToken  = pageToken;
                adUnitResponse           = adUnitRequest.Execute();

                if (adUnitResponse.Items != null && adUnitResponse.Items.Count > 0)
                {
                    foreach (var adUnit in adUnitResponse.Items)
                    {
                        Console.WriteLine("Ad unit with code \"{0}\", name \"{1}\" and status \"{2}\" " +
                                          "was found.", adUnit.Code, adUnit.Name, adUnit.Status);
                    }
                }
                else
                {
                    Console.WriteLine("No ad units found.");
                }

                pageToken = adUnitResponse.NextPageToken;
            } while (pageToken != null);
            Console.WriteLine();
        }
Exemplo n.º 3
0
    IEnumerator GetData(string url)
    {
        UnityWebRequest request = UnityWebRequest.Get(url);

        yield return(request.SendWebRequest());

        if (!request.isNetworkError && !request.isHttpError)
        {
            AdUnits adUnits = JsonUtility.FromJson <AdUnits> (request.downloadHandler.text);

            AdmobServerAdUnits.AppId          = adUnits.AppID;
            AdmobServerAdUnits.BannerId       = adUnits.BannerID;
            AdmobServerAdUnits.InterstitialId = adUnits.InterstitialID;
            AdmobServerAdUnits.RewardId       = adUnits.RewardID;

            adUnitsLoaded = true;

            Debug.Log("<color=green>[AdmobServer] Ad units loaded successfully from server.</color>");
        }
        else
        {
            Debug.LogError("[AdmobServer] Error: " + request.error);
        }

        request.Dispose();
    }
Exemplo n.º 4
0
        protected virtual void PopulateAdManager()
        {
            // register first AD (leaderboard)
            AdUnits.Add(AdManagerModel.Register(AdType.Leaderboard));

            AdManagerModel.AddSetting("site", "betterswing");
            AdManagerModel.AddSetting("network", "test");
            AdManagerModel.AddSetting("page", "show");
            //AdSettings.KeyValuePairs.Add("section", "show");
            //AdSettings.KeyValuePairs.Add("liveinsite", "show");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Placeholder that is replaced with ads.
        /// </summary>
        /// <param name="unitName">Name of the ad unit as set in DFP.</param>
        /// <param name="size">Specify creative sizes in the googletag.defineSlot() function. To allow multiple sizes to serve to the ad slot, you can use a comma-separated list.</param>
        /// <param name="cssClass">CSS class to add to the ad unit div container.</param>
        /// <param name="tagName">Type of parent container, must be block</param>
        /// <param name="sizeMapping">Specify creative sizes in the googletag.defineSlot() function. To allow multiple sizes to serve to the ad slot, you can use a comma-separated list.</param>
        /// <param name="display">Should display be called when the dfp script is initialised?</param>
        /// <param name="targeting">GA slot specific targeting</param>
        /// <returns>HTML container object.</returns>
        public static IHtmlString Placeholder(string unitName, string size, string cssClass, string tagName, string sizeMapping, bool display, Dictionary <string, string> targeting)
        {
            if (String.IsNullOrWhiteSpace(unitName))
            {
                throw new ArgumentNullException("unitName");
            }

            cssClass    = cssClass ?? "";
            tagName     = tagName ?? "div";
            targeting   = targeting ?? new Dictionary <string, string>();
            sizeMapping = sizeMapping ?? "";

            if (String.IsNullOrWhiteSpace(tagName))
            {
                throw new ArgumentNullException("tagName");
            }

            var containerId = "div-gpt-ad-" + _adCounter;

            string placeholder = String.Format(
                CultureInfo.InvariantCulture,
                "<{0} id=\"{1}\" class=\"{2}\" data-cb-ad-id=\"{3}\"><!-- {3} --></{0}>",
                tagName,
                containerId,
                cssClass,
                unitName);

            var unit = new AdUnit
            {
                UnitName  = unitName,
                Size      = size,
                Display   = display,
                Id        = containerId,
                Targeting = targeting
            };

            if (!string.IsNullOrWhiteSpace(sizeMapping))
            {
                // Confirm the mapping exists
                if (!SizeUnits.ContainsKey(sizeMapping))
                {
                    throw new ArgumentException(String.Format("Size unit '{0}' not defined. Sizes must be defined before adding to a unit.", sizeMapping), "sizeMapping");
                }
                unit.SizeMapping = sizeMapping;
            }

            AdUnits.Add(unit);

            _adCounter++;

            return(new HtmlString(placeholder));
        }
Exemplo n.º 6
0
    /// <summary>
    /// Whether the interstitial ad is ready to be shown or not.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    public static bool IsInterstitialReady(string adUnitId)
    {
        ValidateInit();

        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            return(plugin.IsInterstitialReady());
        }
        ReportAdUnitNotFound(adUnitId);
        return(false);
    }
Exemplo n.º 7
0
    /// <summary>
    /// Whether a rewarded video is ready to play for this ad unit.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    /// <returns>`true` if a rewarded ad for the given ad unit id is loaded and ready to be shown; false othewise
    /// </returns>
    public static bool HasRewardedVideo(string adUnitId)
    {
        ValidateInit();

        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            return(plugin.HasRewardedVideo());
        }
        ReportAdUnitNotFound(adUnitId);
        return(false);
    }
Exemplo n.º 8
0
    /// <summary>
    /// Selects the reward to give the user when the ad has finished playing.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    /// <param name="selectedReward">See <see cref="MoPub.Reward"/>.</param>
    public static void SelectReward(string adUnitId, Reward selectedReward)
    {
        ValidateInit();

        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.SelectReward(selectedReward);
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 9
0
    /// <summary>
    /// Destroys an already-loaded interstitial ad.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    public static void DestroyInterstitialAd(string adUnitId)
    {
        ValidateInit();

        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.DestroyInterstitialAd();
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 10
0
    /// <summary>
    /// Enables or disables banners automatically refreshing every 30 seconds.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    /// <param name="enabled">Whether to enable or disable autorefresh.</param>
    public static void SetAutorefresh(string adUnitId, bool enabled)
    {
        ValidateInit();

        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.SetAutorefresh(enabled);
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 11
0
    /// <summary>
    /// If the rewarded video ad has loaded, this will take over the screen and show the ad.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    /// <param name="customData">An optional string with custom data for the ad.</param>
    /// <remarks><see cref="MoPubManager.OnRewardedVideoLoadedEvent"/> must have been triggered already.</remarks>
    public static void ShowRewardedVideo(string adUnitId, string customData = null)
    {
        ValidateInit();

        MoPubLog.Log("ShowRewardedVideo", MoPubLog.AdLogEvent.ShowAttempted);
        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.ShowRewardedVideo(customData);
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 12
0
    /// <summary>
    /// If the interstitial ad has loaded, this will take over the screen and show the ad.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    /// <remarks><see cref="MoPubManager.OnInterstitialLoadedEvent"/> must have been triggered already.</remarks>
    public static void ShowInterstitialAd(string adUnitId)
    {
        ValidateInit();

        MoPubLog.Log("ShowInterstitialAd", MoPubLog.AdLogEvent.ShowAttempted);
        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.ShowInterstitialAd();
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 13
0
    /// <summary>
    /// Requests an interstitial ad with the given (optional) keywords to be loaded. The two possible resulting events
    /// are <see cref="MoPubManager.OnInterstitialLoadedEvent"/> and
    /// <see cref="MoPubManager.OnInterstitialFailedEvent"/>.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    /// <param name="keywords">An optional comma-separated string with the desired keywords for this ad.</param>
    /// <param name="userDataKeywords">An optional comma-separated string with user data for this ad.</param>
    /// <remarks>If a user is in a General Data Protection Regulation (GDPR) region and MoPub doesn't obtain consent
    /// from the user, "keywords" will be sent to the server but "userDataKeywords" will be excluded.
    /// (See <see cref="CanCollectPersonalInfo"/>).</remarks>
    public static void RequestInterstitialAd(string adUnitId, string keywords = "", string userDataKeywords = "")
    {
        ValidateInit();

        MoPubLog.Log("RequestInterstitialAd", MoPubLog.AdLogEvent.LoadAttempted);
        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.RequestInterstitialAd(keywords, userDataKeywords);
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 14
0
    /// <summary>
    /// Refreshes the banner ad regardless of whether autorefresh is enabled or not.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    public static void ForceRefresh(string adUnitId)
    {
        ValidateInit();

        MoPubLog.Log("ForceRefresh", MoPubLog.AdLogEvent.ShowAttempted);
        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.ForceRefresh();
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 15
0
    /// <summary>
    /// Sets the desired keywords and reloads the banner ad.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    /// <param name="keywords">A comma-separated string with the desired keywords for this ad.</param>
    /// <param name="userDataKeywords">An optional comma-separated string with user data for this ad.</param>
    /// <remarks>If a user is in a General Data Protection Regulation (GDPR) region and MoPub doesn't obtain consent
    /// from the user, "keywords" will be sent to the server but "userDataKeywords" will be excluded.
    /// (See <see cref="CanCollectPersonalInfo"/>).</remarks>
    public static void RefreshBanner(string adUnitId, string keywords, string userDataKeywords = "")
    {
        ValidateInit();

        MoPubLog.Log("RefreshBanner", MoPubLog.AdLogEvent.ShowAttempted);
        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.RefreshBanner(keywords, userDataKeywords);
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 16
0
    public static void RequestNativeAd(string adUnitId)
    {
        ValidateInit();

        MoPubLog.Log("RequestNativeAd", MoPubLog.AdLogEvent.LoadAttempted);
        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.RequestNativeAd();
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 17
0
    public static void CreateBanner(string adUnitId, AdPosition position,
                                    BannerType bannerType = BannerType.Size320x50)
    {
        ValidateInit();

        MoPubLog.Log("CreateBanner", MoPubLog.AdLogEvent.LoadAttempted);
        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.CreateBanner(position, bannerType);
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 18
0
    /// <summary>
    /// Retrieves a list of available rewards for the given ad unit id.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    /// <returns>A list of <see cref="MoPub.Reward"/>s for the given ad unit id.</returns>
    public static List <Reward> GetAvailableRewards(string adUnitId)
    {
        ValidateInit();

        MoPubAdUnit plugin;

        if (!AdUnits.TryGetValue(adUnitId, out plugin))
        {
            ReportAdUnitNotFound(adUnitId);
            return(null);
        }

        var rewards = plugin.GetAvailableRewards();

        Debug.Log(String.Format("GetAvailableRewards found {0} rewards for ad unit {1}", rewards.Count, adUnitId));
        return(rewards);
    }
Exemplo n.º 19
0
    /// <summary>
    /// Shows or hides an already-loaded banner ad.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    /// <param name="shouldShow">A bool with `true` to show the ad, or `false` to hide it.</param>
    /// <remarks>Banners are automatically shown after first loading.</remarks>
    public static void ShowBanner(string adUnitId, bool shouldShow)
    {
        ValidateInit();

        if (shouldShow)
        {
            MoPubLog.Log("ShowBanner", MoPubLog.AdLogEvent.ShowAttempted);
        }
        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.ShowBanner(shouldShow);
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 20
0
    /// <summary>
    /// Requests an rewarded video ad with the given (optional) configuration to be loaded. The two possible resulting
    /// events are <see cref="MoPubManager.OnRewardedVideoLoadedEvent"/> and
    /// <see cref="MoPubManager.OnRewardedVideoFailedEvent"/>.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    /// <param name="mediationSettings">See <see cref="MoPub.SdkConfiguration.MediationSettings"/>.</param>
    /// <param name="keywords">An optional comma-separated string with the desired keywords for this ad.</param>
    /// <param name="userDataKeywords">An optional comma-separated string with user data for this ad.</param>
    /// <param name="latitude">An optional location latitude to be used for this ad.</param>
    /// <param name="longitude">An optional location longitude to be used for this ad.</param>
    /// <param name="customerId">An optional string to indentify this user within this app. </param>
    /// <remarks>If a user is in a General Data Protection Regulation (GDPR) region and MoPub doesn't obtain consent
    /// from the user, "keywords" will be sent to the server but "userDataKeywords" will be excluded.
    /// (See <see cref="CanCollectPersonalInfo"/>).</remarks>
    public static void RequestRewardedVideo(string adUnitId, List <LocalMediationSetting> mediationSettings = null,
                                            string keywords   = null, string userDataKeywords     = null,
                                            double latitude   = LatLongSentinel, double longitude = LatLongSentinel,
                                            string customerId = null)
    {
        ValidateInit();

        MoPubLog.Log("RequestRewardedVideo", MoPubLog.AdLogEvent.LoadAttempted);
        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.RequestRewardedVideo(mediationSettings, keywords, userDataKeywords, latitude, longitude, customerId);
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 21
0
    /// <summary>
    /// Requests a banner ad and immediately shows it once loaded.
    /// </summary>
    /// <param name="adUnitId">A string with the ad unit id.</param>
    /// <param name="position">Where in the screen to position the loaded ad. See <see cref="MoPub.AdPosition"/>.
    /// </param>
    /// <param name="maxAdSize">The maximum size of the banner to load. See <see cref="MoPub.MaxAdSize"/>.</param>
    public static void RequestBanner(string adUnitId, AdPosition position,
                                     MaxAdSize maxAdSize = MaxAdSize.Width320Height50)
    {
        ValidateInit();

        var width  = maxAdSize.Width();
        var height = maxAdSize.Height();

        MoPubLog.Log("RequestBanner", MoPubLog.AdLogEvent.LoadAttempted);
        MoPubLog.Log("RequestBanner", "Size requested: " + width + "x" + height);
        MoPubAdUnit plugin;

        if (AdUnits.TryGetValue(adUnitId, out plugin))
        {
            plugin.RequestBanner(width, height, position);
        }
        else
        {
            ReportAdUnitNotFound(adUnitId);
        }
    }
Exemplo n.º 22
0
        public AdUnitViewModel Register(AdType type)
        {
            // Get position of current requested Ad
            int position = 1;

            if (AdsCounterByType.ContainsKey(type))
            {
                position = ++AdsCounterByType[type];
            }
            else
            {
                AdsCounterByType.Add(type, position);
            }

            // Instanciate AdUnit
            AdUnitViewModel adUnit = new AdUnitViewModel(type, position);

            // Add to the list
            AdUnits.Add(adUnit);
            return(adUnit);
        }
        /// <summary>
        /// Prints all ad units corresponding to a specified custom channel.
        /// </summary>
        /// <param name="adClientId">The ID for the ad client to be used.</param>
        /// <param name="customChannelId">The ID for the custom channel to be used.</param>
        private void DisplayAllAdUnits(string adClientId, string customChannelId)
        {
            Console.WriteLine("=================================================================");
            Console.WriteLine("Listing all ad units for custom channel {0}", customChannelId);
            Console.WriteLine("=================================================================");

            // Retrieve ad client list in pages and display data as we receive it.
            string  pageToken      = null;
            AdUnits adUnitResponse = null;

            do
            {
                var adUnitRequest = service.Accounts.Customchannels.Adunits.List(
                    adSenseAccount.Id,
                    adClientId,
                    customChannelId);
                adUnitRequest.MaxResults = maxListPageSize;
                adUnitRequest.PageToken  = pageToken;
                adUnitResponse           = adUnitRequest.Execute();

                if (!adUnitResponse.Items.IsNullOrEmpty())
                {
                    foreach (var adUnit in adUnitResponse.Items)
                    {
                        Console.WriteLine(
                            "Ad unit with code \"{0}\", name \"{1}\" and status \"{2}\" was found.",
                            adUnit.Code,
                            adUnit.Name,
                            adUnit.Status);
                    }
                }
                else
                {
                    Console.WriteLine("No ad units found.");
                }

                pageToken = adUnitResponse.NextPageToken;
            }while (pageToken != null);
            Console.WriteLine();
        }
        /// <summary>
        /// Gets and prints all ad units in an ad client.
        /// </summary>
        /// <param name="adClientId">The ID for the ad client to be used.</param>
        /// <returns>The last page of retrieved accounts.</returns>
        private AdUnits GetAllAdUnits(string adClientId)
        {
            Console.WriteLine("=================================================================");
            Console.WriteLine("Listing all ad units for ad client {0}", adClientId);
            Console.WriteLine("=================================================================");

            // Retrieve ad client list in pages and display data as we receive it.
            string  pageToken      = null;
            AdUnits adUnitResponse = null;

            do
            {
                var adUnitRequest = service.Adunits.List(adClientId);
                adUnitRequest.MaxResults = maxListPageSize;
                adUnitRequest.PageToken  = pageToken;
                adUnitResponse           = adUnitRequest.Execute();

                if (!adUnitResponse.Items.IsNullOrEmpty())
                {
                    foreach (var adUnit in adUnitResponse.Items)
                    {
                        Console.WriteLine(
                            "Ad unit with code \"{0}\", name \"{1}\" and status \"{2}\" was found.",
                            adUnit.Code,
                            adUnit.Name,
                            adUnit.Status);
                    }
                }
                else
                {
                    Console.WriteLine("No ad units found.");
                }

                pageToken = adUnitResponse.NextPageToken;
            }while (pageToken != null);
            Console.WriteLine();

            // Return the last page of ad units, so that the main sample has something to run.
            return(adUnitResponse);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Defines an ad unit in publisher tags without creating the container on the page.
        /// </summary>
        /// <param name="unitName">Name of the ad unit as set in DFP.</param>
        /// <param name="size">Ad unit size.</param>
        /// <param name="id">ID of the ad unit container.</param>
        public static void DefineAdUnit(string unitName, string size, string id)
        {
            if (String.IsNullOrWhiteSpace(unitName))
            {
                throw new ArgumentNullException("unitName");
            }
            if (String.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException("id");
            }

            var unit = new AdUnit
            {
                UnitName = unitName,
                Size     = size,
                Display  = false,
                Id       = id
            };


            AdUnits.Add(unit);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Runs this sample.
        /// </summary>
        /// <param name="adsense">AdSense service object on which to run the requests.</param>
        /// <param name="adClientId">The ID for the ad client to be used.</param>
        /// <param name="maxPageSize">The maximum page size to retrieve.</param>
        /// <returns>The last page of retrieved accounts.</returns>
        public static AdUnits Run(AdsenseService adsense, string adClientId, int maxPageSize)
        {
            CommandLine.WriteLine("=================================================================");
            CommandLine.WriteLine("Listing all ad units for ad client {0}", adClientId);
            CommandLine.WriteLine("=================================================================");

            // Retrieve ad client list in pages and display data as we receive it.
            string  pageToken      = null;
            AdUnits adUnitResponse = null;

            do
            {
                var adUnitRequest = adsense.Adunits.List(adClientId);
                adUnitRequest.MaxResults = maxPageSize;
                adUnitRequest.PageToken  = pageToken;
                adUnitResponse           = adUnitRequest.Fetch();

                if (adUnitResponse.Items != null && adUnitResponse.Items.Count > 0)
                {
                    foreach (var adUnit in adUnitResponse.Items)
                    {
                        CommandLine.WriteLine("Ad unit with code \"{0}\", name \"{1}\" and status \"{2}\" " +
                                              "was found.", adUnit.Code, adUnit.Name, adUnit.Status);
                    }
                }
                else
                {
                    CommandLine.WriteLine("No ad units found.");
                }

                pageToken = adUnitResponse.NextPageToken;
            } while (pageToken != null);

            CommandLine.WriteLine();

            // Return the last page of ad units, so that the main sample has something to run.
            return(adUnitResponse);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Runs this sample.
        /// </summary>
        /// <param name="adsense">AdSense service object on which to run the requests.</param>
        /// <param name="adClientId">The ID for the ad client to be used.</param>
        /// <param name="customChannelId">The ID for the custom channel to be used.</param>
        /// <param name="maxPageSize">The maximum page size to retrieve.</param>
        /// <returns>The last page of retrieved accounts.</returns>
        public static void Run(AdsenseService adsense, string adClientId, string customChannelId,
                               int maxPageSize)
        {
            CommandLine.WriteLine("=================================================================");
            CommandLine.WriteLine("Listing all ad units for custom channel {0}", customChannelId);
            CommandLine.WriteLine("=================================================================");

            // Retrieve ad client list in pages and display data as we receive it.
            string  pageToken      = null;
            AdUnits adUnitResponse = null;

            do
            {
                var adUnitRequest = adsense.Customchannels.Adunits.List(adClientId, customChannelId);
                adUnitRequest.MaxResults = maxPageSize;
                adUnitRequest.PageToken  = pageToken;
                adUnitResponse           = adUnitRequest.Fetch();

                if (adUnitResponse.Items != null && adUnitResponse.Items.Count > 0)
                {
                    foreach (var adUnit in adUnitResponse.Items)
                    {
                        CommandLine.WriteLine("Ad unit with code \"{0}\", name \"{1}\" and status \"{2}\" " +
                                              "was found.", adUnit.Code, adUnit.Name, adUnit.Status);
                    }
                }
                else
                {
                    CommandLine.WriteLine("No ad units found.");
                }

                pageToken = adUnitResponse.NextPageToken;
            } while (pageToken != null);

            CommandLine.WriteLine();
        }
Exemplo n.º 28
0
 public override void RegisterAds(AdManagerViewModel adManager)
 {
     AdUnits.Add(adManager.Register(AdType));
 }