/// <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;
                operation.@operator = 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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">The campaign ID.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the VideoTargetingGroupService.
            VideoTargetingGroupService videoTargetingGroupService = (VideoTargetingGroupService)
                                                                    user.GetService(AdWordsService.v201406.VideoTargetingGroupService);

            int offset = 0;

            TargetingGroupPage page = new TargetingGroupPage();

            try {
                // Create selector.
                TargetingGroupSelector selector = new TargetingGroupSelector();
                selector.campaignIds = new long[] { campaignId };

                selector.paging = new Paging();

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

                    // Get all targeting groups for this account.
                    page = videoTargetingGroupService.get(selector);

                    // Display the results.
                    if (page != null && page.entries != null)
                    {
                        int i = offset;
                        foreach (TargetingGroup targetingGroup in page.entries)
                        {
                            Console.WriteLine("{0}) Targeting group ID {1}, campaign ID {2} and name '{3}'",
                                              (i + 1), targetingGroup.id, targetingGroup.campaignId, targetingGroup.name);

                            i++;
                        }
                    }
                    else
                    {
                        Console.WriteLine("No targeting groups were found.");
                    }
                    offset += PAGE_SIZE;
                } while (offset < page.totalNumEntries);
                Console.WriteLine("Number of targeting groups found: {0}", page.totalNumEntries);
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to get targeting groups.", ex);
            }
        }