/// <summary>
        /// Run the example.
        /// </summary>
        /// <param name="parsedArgs">Parsed arguments for the example.</param>
        protected override void Run(Dictionary <string, object> parsedArgs)
        {
            string accountId = (string)parsedArgs["account_id"];
            string parent    = $"buyers/{accountId}";
            string pageToken = null;

            Console.WriteLine(@"Listing creatives for buyer account ""{0}""", parent);
            do
            {
                BuyersResource.CreativesResource.ListRequest request =
                    rtbService.Buyers.Creatives.List(parent);
                request.Filter    = (string)parsedArgs["filter"];
                request.PageSize  = (int)parsedArgs["pageSize"];
                request.PageToken = pageToken;
                request.View      = (BuyersResource.CreativesResource.ListRequest.ViewEnum)Enum.Parse(
                    typeof(BuyersResource.CreativesResource.ListRequest.ViewEnum),
                    (string)parsedArgs["view"],
                    false);

                ListCreativesResponse page = null;

                try
                {
                    page = request.Execute();
                }
                catch (System.Exception exception)
                {
                    throw new ApplicationException(
                              $"Real-time Bidding API returned error response:\n{exception.Message}");
                }

                var creatives = page.Creatives;
                pageToken = page.NextPageToken;

                if (creatives == null)
                {
                    Console.WriteLine("No creatives found for buyer account.");
                }
                else
                {
                    foreach (Creative creative in creatives)
                    {
                        Utilities.PrintCreative(creative);
                    }
                }
            }while(pageToken != null);
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            // See the README.md for details of these fields.
            // Retrieved from https://console.developers.google.com
            var ServiceKeyFilePath = "PATH TO JSON KEY FILE HERE";

            // Name of the buyer resource for which the API call is being made.
            var buyerName = "INSERT_BUYER_RESOURCE_NAME_HERE";

            // Retrieve credential parameters from the key JSON file.
            var credentialParameters = NewtonsoftJsonSerializer.Instance
                                       .Deserialize <JsonCredentialParameters>(
                System.IO.File.ReadAllText(ServiceKeyFilePath));

            // Create the credentials.
            var credentialInitializer = new ServiceAccountCredential.Initializer(
                credentialParameters.ClientEmail)
            {
                Scopes = new[] { RealTimeBiddingService.Scope.RealtimeBidding }
            }.FromPrivateKey(credentialParameters.PrivateKey);

            var oAuth2Credentials = new ServiceAccountCredential(credentialInitializer);

            // Use the credentials to create a client for the API service.
            var serviceInitializer = new BaseClientService.Initializer
            {
                HttpClientInitializer = oAuth2Credentials,
                ApplicationName       = "FirstAPICall"
            };

            var realtimebidding = new RealTimeBiddingService(serviceInitializer);

            // Call the buyers.creatives.list method to list creatives for the given buyer.
            BuyersResource.CreativesResource.ListRequest request =
                realtimebidding.Buyers.Creatives.List(buyerName);
            request.View = BuyersResource.CreativesResource.ListRequest.ViewEnum.FULL;

            IList <Creative> creatives = request.Execute().Creatives;

            foreach (Creative creative in creatives)
            {
                Console.WriteLine("* Creative name: {0}", creative.Name);
            }

            Console.ReadLine();
        }