Register for one of our Google Ads API workshops (March 6, 2019 - April 23, 2019).

Basic Operations Samples

The code samples below provide examples of basic operations using the AdWords API. Client Library.

Add demographic target criteria to an ad group

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example adds demographic target criteria to an ad group. To get
    ''' ad groups, run AddAdGroup.vb.
    ''' </summary>
    Public Class AddAdGroupDemographicCriteria
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New AddAdGroupDemographicCriteria
            Console.WriteLine(codeExample.Description)
            Try
                Dim adGroupId As Long = Long.Parse("INSERT_ADGROUP_ID_HERE")
                codeExample.Run(New AdWordsUser, adGroupId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return _
                    "This code example adds demographic target criteria to an ad group. To get " &
                    "ad groups, run AddAdGroup.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adGroupId">Id of the ad group to which criteria are
        ''' added.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long)
            Using adGroupCriterionService As AdGroupCriterionService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupCriterionService),
                AdGroupCriterionService)

                ' Create biddable ad group criterion for gender
                Dim genderTarget As New Gender()
                ' Criterion Id for male. The IDs can be found here
                ' https://developers.google.com/adwords/api/docs/appendix/genders
                genderTarget.id = 10

                Dim genderBiddableAdGroupCriterion As New BiddableAdGroupCriterion()
                genderBiddableAdGroupCriterion.adGroupId = adGroupId
                genderBiddableAdGroupCriterion.criterion = genderTarget

                ' Create negative ad group criterion for age range
                Dim ageRangeNegative As New AgeRange()
                ' Criterion Id for age 18 to 24. The IDs can be found here
                ' https://developers.google.com/adwords/api/docs/appendix/ages

                ageRangeNegative.id = 503001
                Dim ageRangeNegativeAdGroupCriterion As New NegativeAdGroupCriterion()
                ageRangeNegativeAdGroupCriterion.adGroupId = adGroupId
                ageRangeNegativeAdGroupCriterion.criterion = ageRangeNegative

                ' Create operations.
                Dim genderBiddableAdGroupCriterionOperation As New AdGroupCriterionOperation()
                genderBiddableAdGroupCriterionOperation.operand = genderBiddableAdGroupCriterion
                genderBiddableAdGroupCriterionOperation.operator = [Operator].ADD

                Dim ageRangeNegativeAdGroupCriterionOperation As New AdGroupCriterionOperation()
                ageRangeNegativeAdGroupCriterionOperation.operand = ageRangeNegativeAdGroupCriterion
                ageRangeNegativeAdGroupCriterionOperation.operator = [Operator].ADD

                Dim operations As New List(Of Operation)
                operations.Add(genderBiddableAdGroupCriterionOperation)
                operations.Add(ageRangeNegativeAdGroupCriterionOperation)

                Try
                    ' Add ad group criteria.
                    Dim result As AdGroupCriterionReturnValue = adGroupCriterionService.mutate(
                        CType(operations.ToArray, AdGroupCriterionOperation()))

                    ' Display ad group criteria.
                    If (Not result Is Nothing) AndAlso Not (result.value Is Nothing) Then
                        For Each adGroupCriterionResult As AdGroupCriterion In result.value
                            Console.WriteLine(
                                "Ad group criterion with ad group id '{0}', criterion id " &
                                "'{1}', and type '{2}' was added.",
                                adGroupCriterionResult.adGroupId,
                                adGroupCriterionResult.criterion.id,
                                adGroupCriterionResult.criterion.CriterionType)
                        Next
                    Else
                        Console.WriteLine("No ad group criteria were added.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to create ad group criteria.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Add ad groups to a campaign

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example illustrates how to create ad groups. To create
    ''' campaigns, run AddCampaigns.vb.
    ''' </summary>
    Public Class AddAdGroups
        Inherits ExampleBase

        ''' <summary>
        ''' Number of items being added / updated in this code example.
        ''' </summary>
        Const NUM_ITEMS As Integer = 5

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New AddAdGroups
            Console.WriteLine(codeExample.Description)
            Try
                Dim campaignId As Long = Long.Parse("INSERT_CAMPAIGN_ID_HERE")
                codeExample.Run(New AdWordsUser, campaignId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return _
                    "This code example illustrates how to create ad groups. To create campaigns," &
                    " run AddCampaigns.vb"
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="campaignId">Id of the campaign to which ad groups are
        ''' added.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal campaignId As Long)
            Using adGroupService As AdGroupService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupService),
                AdGroupService)

                Dim operations As New List(Of AdGroupOperation)

                For i As Integer = 1 To NUM_ITEMS
                    ' Create the ad group.
                    Dim adGroup As New AdGroup
                    adGroup.name = String.Format("Earth to Mars Cruises #{0}",
                                                 ExampleUtilities.GetRandomString)
                    adGroup.status = AdGroupStatus.ENABLED
                    adGroup.campaignId = campaignId

                    ' Set the ad group bids.
                    Dim biddingConfig As New BiddingStrategyConfiguration()

                    Dim cpcBid As New CpcBid()
                    cpcBid.bid = New Money()
                    cpcBid.bid.microAmount = 10000000

                    biddingConfig.bids = New Bids() {cpcBid}

                    adGroup.biddingStrategyConfiguration = biddingConfig

                    ' Optional: Set targeting restrictions.
                    ' Depending on the criterionTypeGroup value, most TargetingSettingDetail
                    ' only affect Display campaigns. However, the USER_INTEREST_AND_LIST value
                    ' works for RLSA campaigns - Search campaigns targeting using a
                    ' remarketing list.
                    Dim targetingSetting As New TargetingSetting()

                    ' Restricting to serve ads that match your ad group placements.
                    ' This is equivalent to choosing "Target and bid" in the UI.
                    Dim placementDetail As New TargetingSettingDetail()
                    placementDetail.criterionTypeGroup = CriterionTypeGroup.PLACEMENT
                    placementDetail.targetAll = False

                    ' Using your ad group verticals only for bidding. This is equivalent
                    ' to choosing "Bid only" in the UI.
                    Dim verticalDetail As New TargetingSettingDetail()
                    verticalDetail.criterionTypeGroup = CriterionTypeGroup.VERTICAL
                    verticalDetail.targetAll = True

                    targetingSetting.details = New TargetingSettingDetail() _
                        {placementDetail, verticalDetail}

                    adGroup.settings = New Setting() {targetingSetting}

                    ' Set the rotation mode.
                    Dim rotationMode As New AdGroupAdRotationMode
                    rotationMode.adRotationMode = AdRotationMode.OPTIMIZE
                    adGroup.adGroupAdRotationMode = rotationMode

                    ' Create the operation.
                    Dim operation As New AdGroupOperation
                    operation.operator = [Operator].ADD
                    operation.operand = adGroup

                    operations.Add(operation)
                Next

                Try
                    ' Create the ad group.
                    Dim retVal As AdGroupReturnValue = adGroupService.mutate(operations.ToArray())

                    ' Display the results.
                    If ((Not retVal Is Nothing) AndAlso (Not retVal.value Is Nothing) AndAlso
                        (retVal.value.Length > 0)) Then
                        For Each newAdGroup As AdGroup In retVal.value
                            Console.WriteLine(
                                "Ad group with id = '{0}' and name = '{1}' was created.",
                                newAdGroup.id, newAdGroup.name)
                        Next
                    Else
                        Console.WriteLine("No ad groups were created.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to create ad groups.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Add campaigns

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example adds campaigns. To get campaigns, run GetCampaigns.vb.
    ''' </summary>
    Public Class AddCampaigns
        Inherits ExampleBase

        ''' <summary>
        ''' Number of items being added / updated in this code example.
        ''' </summary>
        Const NUM_ITEMS As Integer = 5

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New AddCampaigns
            Console.WriteLine(codeExample.Description)
            Try
                codeExample.Run(New AdWordsUser)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return "This code example adds campaigns. To get campaigns, run GetCampaigns.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        Public Sub Run(ByVal user As AdWordsUser)
            Using campaignService As CampaignService = CType(
                user.GetService(
                    AdWordsService.v201809.CampaignService),
                CampaignService)

                Dim budget As Budget = CreateBudget(user)

                Dim operations As New List(Of CampaignOperation)

                For i As Integer = 1 To NUM_ITEMS
                    ' Create the campaign.
                    Dim campaign As New Campaign
                    campaign.name = "Interplanetary Cruise #" & ExampleUtilities.GetRandomString
                    campaign.advertisingChannelType = AdvertisingChannelType.SEARCH

                    ' Recommendation: Set the campaign to PAUSED when creating it to prevent
                    ' the ads from immediately serving. Set to ENABLED once you've added
                    ' targeting and the ads are ready to serve.
                    campaign.status = CampaignStatus.PAUSED

                    Dim biddingConfig As New BiddingStrategyConfiguration()
                    biddingConfig.biddingStrategyType = BiddingStrategyType.MANUAL_CPC
                    campaign.biddingStrategyConfiguration = biddingConfig

                    ' Set the campaign budget.
                    campaign.budget = New Budget
                    campaign.budget.budgetId = budget.budgetId

                    ' Set the campaign network options.
                    campaign.networkSetting = New NetworkSetting
                    campaign.networkSetting.targetGoogleSearch = True
                    campaign.networkSetting.targetSearchNetwork = True
                    campaign.networkSetting.targetContentNetwork = False
                    campaign.networkSetting.targetPartnerSearchNetwork = False

                    ' Set the campaign geo target and keyword match settings.
                    Dim geoSetting As New GeoTargetTypeSetting
                    geoSetting.positiveGeoTargetType =
                        GeoTargetTypeSettingPositiveGeoTargetType.DONT_CARE
                    geoSetting.negativeGeoTargetType =
                        GeoTargetTypeSettingNegativeGeoTargetType.DONT_CARE

                    campaign.settings = New Setting() {geoSetting}

                    ' Optional: Set the start date.
                    campaign.startDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd")

                    ' Optional: Set the end date.
                    campaign.endDate = DateTime.Now.AddYears(1).ToString("yyyyMMdd")

                    ' Optional: Set the frequency cap.
                    Dim frequencyCap As New FrequencyCap
                    frequencyCap.impressions = 5
                    frequencyCap.level = Level.ADGROUP
                    frequencyCap.timeUnit = TimeUnit.DAY
                    campaign.frequencyCap = frequencyCap

                    ' Create the operation.
                    Dim operation As New CampaignOperation
                    operation.operator = [Operator].ADD
                    operation.operand = campaign
                    operations.Add(operation)
                Next

                Try
                    ' Add the campaign.
                    Dim retVal As CampaignReturnValue = campaignService.mutate(operations.ToArray())

                    ' Display the results.
                    If ((Not retVal Is Nothing) AndAlso (Not retVal.value Is Nothing) AndAlso
                        (retVal.value.Length > 0)) Then
                        For Each newCampaign As Campaign In retVal.value
                            Console.WriteLine(
                                "Campaign with name = '{0}' and id = '{1}' was added.",
                                newCampaign.name,
                                newCampaign.id)
                        Next
                    Else
                        Console.WriteLine("No campaigns were added.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to add campaigns.", e)
                End Try
            End Using
        End Sub

        ''' <summary>
        ''' Creates the budget.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <returns>The budget instance.</returns>
        Private Shared Function CreateBudget(user As AdWordsUser) As Budget
            Using budgetService As BudgetService = CType(
                user.GetService(
                    AdWordsService.v201809.BudgetService),
                BudgetService)

                ' Create the campaign budget.
                Dim budget As New Budget
                budget.name = "Interplanetary Cruise Budget #" & ExampleUtilities.GetRandomString
                budget.deliveryMethod = BudgetBudgetDeliveryMethod.STANDARD
                budget.amount = New Money
                budget.amount.microAmount = 50000000

                Dim budgetOperation As New BudgetOperation
                budgetOperation.operator = [Operator].ADD
                budgetOperation.operand = budget

                Try
                    Dim budgetRetval As BudgetReturnValue = budgetService.mutate(
                        New BudgetOperation() {budgetOperation})
                    Return budgetRetval.value(0)
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to add shared budget.", e)
                End Try
            End Using
        End Function
    End Class
End Namespace

Add expanded text ads to an ad group

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example adds expanded text ads to a given ad group. To list
    ''' ad groups, run GetAdGroups.vb.
    ''' </summary>
    Public Class AddExpandedTextAds
        Inherits ExampleBase

        ''' <summary>
        ''' Number of ads being added / updated in this code example.
        ''' </summary>
        Const NUMBER_OF_ADS As Integer = 5

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New AddExpandedTextAds
            Console.WriteLine(codeExample.Description)
            Try
                Dim adGroupId As Long = Long.Parse("INSERT_ADGROUP_ID_HERE")
                codeExample.Run(New AdWordsUser, adGroupId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return "This code example adds expanded text ads to a given ad group. To list " &
                       "ad groups, run GetAdGroups.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adGroupId">Id of the ad group to which ads are added.
        ''' </param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long)
            Using service As AdGroupAdService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupAdService),
                AdGroupAdService)

                Dim operations As New List(Of AdGroupAdOperation)

                For i As Integer = 1 To NUMBER_OF_ADS
                    ' Create the expanded text ad.
                    Dim expandedTextAd As New ExpandedTextAd
                    expandedTextAd.headlinePart1 = "Cruise #" & i.ToString() & " to Mars"
                    expandedTextAd.headlinePart2 = "Best Space Cruise Line"
                    expandedTextAd.headlinePart3 = "For Your Loved Ones"
                    expandedTextAd.description = "Buy your tickets now!"
                    expandedTextAd.description2 = "Discount ends soon"
                    expandedTextAd.finalUrls = New String() {"http://www.example.com/" & i}

                    Dim expandedTextAdGroupAd As New AdGroupAd
                    expandedTextAdGroupAd.adGroupId = adGroupId
                    expandedTextAdGroupAd.ad = expandedTextAd

                    ' Optional: Set the status.
                    expandedTextAdGroupAd.status = AdGroupAdStatus.PAUSED

                    ' Create the operations.
                    Dim operation As New AdGroupAdOperation
                    operation.operator = [Operator].ADD
                    operation.operand = expandedTextAdGroupAd

                    operations.Add(operation)
                Next

                Dim retVal As AdGroupAdReturnValue = Nothing

                Try
                    ' Create the ads.
                    retVal = service.mutate(operations.ToArray())

                    ' Display the results.
                    If ((Not retVal Is Nothing) AndAlso (Not retVal.value Is Nothing)) Then
                        For Each adGroupAd As AdGroupAd In retVal.value
                            Dim newAd As ExpandedTextAd = CType(adGroupAd.ad, ExpandedTextAd)
                            Console.WriteLine(
                                "Expanded text ad with ID '{0}' and headline '{1} - {2}' " +
                                "was added.", newAd.id, newAd.headlinePart1, newAd.headlinePart2)
                        Next
                    Else
                        Console.WriteLine("No expanded text ads were created.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to create expanded text ads.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Add keywords to an ad group

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports System.Web
Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example adds keywords to an ad group. To get ad groups, run
    ''' GetAdGroups.vb.
    ''' </summary>
    Public Class AddKeywords
        Inherits ExampleBase

        ''' <summary>
        ''' Items being added in this code example.
        ''' </summary>
        ReadOnly KEYWORDS As String() = New String() {"mars cruise", "space hotel"}

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New AddKeywords
            Console.WriteLine(codeExample.Description)
            Try
                Dim adGroupId As Long = Long.Parse("INSERT_ADGROUP_ID_HERE")
                codeExample.Run(New AdWordsUser, adGroupId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return "This code example adds keywords to an ad group. To get ad groups, run " &
                       "GetAdGroups.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adGroupId">Id of the ad group to which keywords are added.
        ''' </param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long)
            Using adGroupCriterionService As AdGroupCriterionService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupCriterionService),
                AdGroupCriterionService)

                Dim operations As New List(Of AdGroupCriterionOperation)

                For Each keywordText As String In KEYWORDS
                    ' Create the keyword.
                    Dim keyword As New Keyword
                    keyword.text = keywordText
                    keyword.matchType = KeywordMatchType.BROAD

                    ' Create the biddable ad group criterion.
                    Dim keywordCriterion As New BiddableAdGroupCriterion
                    keywordCriterion.adGroupId = adGroupId
                    keywordCriterion.criterion = keyword

                    ' Optional: Set the user status.
                    keywordCriterion.userStatus = UserStatus.PAUSED

                    ' Optional: Set the keyword destination url.
                    keywordCriterion.finalUrls = New UrlList()
                    keywordCriterion.finalUrls.urls = New String() _
                        {"http://example.com/mars/cruise/?kw=" &
                         HttpUtility.UrlEncode(keywordText)}

                    ' Create the operations.
                    Dim operation As New AdGroupCriterionOperation
                    operation.operator = [Operator].ADD
                    operation.operand = keywordCriterion

                    operations.Add(operation)
                Next

                Try
                    ' Create the keywords.
                    Dim retVal As AdGroupCriterionReturnValue = adGroupCriterionService.mutate(
                        operations.ToArray())

                    ' Display the results.
                    If ((Not retVal Is Nothing) AndAlso (Not retVal.value Is Nothing)) Then
                        For Each adGroupCriterion As AdGroupCriterion In retVal.value
                            ' If you are adding multiple type of criteria, then you may need to
                            ' check for
                            '
                            ' if (adGroupCriterion is Keyword) { ... }
                            '
                            ' to identify the criterion type.
                            Console.WriteLine(
                                "Keyword with ad group id = '{0}, keyword id = '{1}, text = " &
                                "'{2}' and match type = '{3}' was created.",
                                adGroupCriterion.adGroupId,
                                adGroupCriterion.criterion.id,
                                TryCast(adGroupCriterion.criterion, Keyword).text,
                                TryCast(adGroupCriterion.criterion, Keyword).matchType)
                        Next
                    Else
                        Console.WriteLine("No keywords were added.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to create keywords.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Add a responsive search ad to an ad group

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example adds a responsive search ad to a given ad group. To get ad groups,
    ''' run GetAdGroups.vb.
    ''' </summary>
    Public Class AddResponsiveSearchAd
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New AddResponsiveSearchAd
            Console.WriteLine(codeExample.Description)
            Try
                Dim adGroupId As Long = Long.Parse("INSERT_ADGROUP_ID_HERE")
                codeExample.Run(New AdWordsUser, adGroupId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return _
                    "This code example adds a responsive search ad to a given ad group. To get " +
                    "ad groups, run GetAdGroups.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adGroupId">Id of the ad group to which ads are added.
        ''' </param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long)
            Using service As AdGroupAdService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupAdService),
                AdGroupAdService)
                ' Create a responsive search ad.
                Dim responsiveSearchAd As New ResponsiveSearchAd()
                responsiveSearchAd.finalUrls = New String() {"http://www.example.com/cruise"}
                responsiveSearchAd.path1 = "all-inclusive"
                responsiveSearchAd.path2 = "deals"

                Dim textAsset1 As New TextAsset()
                textAsset1.assetText = "Cruise to Mars #" + ExampleUtilities.GetShortRandomString()

                Dim headline1 As New AssetLink()
                headline1.asset = textAsset1
                ' Set a pinning to always choose this asset for HEADLINE_1.
                ' Pinning Is optional; if no pinning is set, then headlines
                ' and descriptions will be rotated and the ones that perform
                ' best will be used more often.
                headline1.pinnedField = ServedAssetFieldType.HEADLINE_1

                Dim textAsset2 As New TextAsset()
                textAsset2.assetText = "Best Space Cruise Line"

                Dim headline2 As New AssetLink()
                headline2.asset = textAsset2

                Dim textAsset3 As New TextAsset()
                textAsset3.assetText = "Experience the Stars"

                Dim headline3 As New AssetLink()
                headline3.asset = textAsset3

                responsiveSearchAd.headlines = New AssetLink() {headline1, headline2, headline3}

                ' Create ad group ad.
                Dim adGroupAd As New AdGroupAd()
                adGroupAd.adGroupId = adGroupId
                adGroupAd.ad = responsiveSearchAd

                ' Optional: Set additional settings.
                adGroupAd.status = AdGroupAdStatus.PAUSED

                ' Create ad group ad operation and add it to the list.
                Dim operation As New AdGroupAdOperation()
                operation.operand = adGroupAd
                operation.operator = [Operator].ADD

                Try
                    ' Add the responsive search ad on the server.
                    Dim retval As AdGroupAdReturnValue = service.mutate(
                        New AdGroupAdOperation() _
                                                                           {operation})

                    ' Print out some information for the created ad.
                    For Each newAdGroupAd As AdGroupAd In retval.value
                        Dim newAd As ResponsiveSearchAd = CType(newAdGroupAd.ad, ResponsiveSearchAd)
                        Console.WriteLine("New responsive search ad with ID {0} was added.",
                                          newAd.id)
                        Console.WriteLine("Headlines:")

                        For Each headline As AssetLink In newAd.headlines
                            Dim textAsset As TextAsset = CType(headline.asset, TextAsset)
                            Console.WriteLine("    {0}", textAsset.assetText)
                            If headline.pinnedFieldSpecified Then
                                Console.WriteLine("      (pinned to {0})", headline.pinnedField)
                            End If
                        Next
                        Console.WriteLine("Descriptions:")
                        For Each description As AssetLink In newAd.descriptions
                            Dim textAsset As TextAsset = CType(description.asset, TextAsset)
                            Console.WriteLine("    {0}", textAsset.assetText)
                            If (description.pinnedFieldSpecified) Then
                                Console.WriteLine("      (pinned to {0})", description.pinnedField)
                            End If
                        Next
                    Next
                Catch e As Exception
                    Throw _
                        New System.ApplicationException("Failed to create responsive search ad.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Get the ad groups of a campaign

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example illustrates how to retrieve all the ad groups for a
    ''' campaign. To create an ad group, run AddAdGroup.vb.
    ''' </summary>
    Public Class GetAdGroups
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New GetAdGroups
            Console.WriteLine(codeExample.Description)
            Try
                Dim campaignId As Long = Long.Parse("INSERT_CAMPAIGN_ID_HERE")
                codeExample.Run(New AdWordsUser, campaignId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return "This code example illustrates how to retrieve all the ad groups for a " &
                       "campaign. To create an ad group, run AddAdGroup.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="campaignId">Id of the campaign for which ad groups are
        ''' retrieved.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal campaignId As Long)
            Using adGroupService As AdGroupService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupService),
                AdGroupService)

                ' Create the selector.
                Dim selector As New Selector
                selector.fields = New String() { _
                                                   AdGroup.Fields.Id, AdGroup.Fields.Name
                                               }

                selector.predicates = New Predicate() { _
                                                          Predicate.Equals(
                                                              AdGroup.Fields.CampaignId,
                                                              campaignId)
                                                      }
                selector.ordering = New OrderBy() {OrderBy.Asc(AdGroup.Fields.Name)}
                selector.paging = Paging.Default

                Dim page As New AdGroupPage

                Try
                    Do
                        ' Get the ad groups.
                        page = adGroupService.get(selector)

                        ' Display the results.
                        If ((Not page Is Nothing) AndAlso (Not page.entries Is Nothing)) Then
                            Dim i As Integer = selector.paging.startIndex
                            For Each adGroup As AdGroup In page.entries
                                Console.WriteLine(
                                    "{0}) Ad group name is ""{1}"" and id is ""{2}"".",
                                    i + 1,
                                    adGroup.name, adGroup.id)
                                i += 1
                            Next
                        End If
                        selector.paging.IncreaseOffset()
                    Loop While (selector.paging.startIndex < page.totalNumEntries)
                    Console.WriteLine("Number of ad groups found: {0}", page.totalNumEntries)
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to retrieve ad group(s).", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Get all campaigns

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example lists all campaigns. To add a campaign, run
    ''' AddCampaign.vb.
    ''' </summary>
    Public Class GetCampaigns
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New GetCampaigns
            Console.WriteLine(codeExample.Description)
            Try
                codeExample.Run(New AdWordsUser)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return _
                    "This code example lists all campaigns. To add a campaign, run AddCampaign.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        Public Sub Run(ByVal user As AdWordsUser)
            Using campaignService As CampaignService = CType(
                user.GetService(
                    AdWordsService.v201809.CampaignService),
                CampaignService)

                ' Create the selector.
                Dim selector As New Selector
                selector.fields = New String() { _
                                                   Campaign.Fields.Id, Campaign.Fields.Name,
                                                   Campaign.Fields.Status
                                               }
                selector.paging = Paging.Default

                Dim page As New CampaignPage

                Try
                    Do
                        ' Get the campaigns.
                        page = campaignService.get(selector)

                        ' Display the results.
                        If ((Not page Is Nothing) AndAlso (Not page.entries Is Nothing)) Then
                            Dim i As Integer = selector.paging.startIndex
                            For Each campaign As Campaign In page.entries
                                Console.WriteLine(
                                    "{0}) Campaign with id = '{1}', name = '{2}' and status = " &
                                    "'{3}' was found.", i + 1, campaign.id, campaign.name,
                                    campaign.status)
                                i += 1
                            Next
                        End If
                        selector.paging.IncreaseOffset()
                    Loop While (selector.paging.startIndex < page.totalNumEntries)
                    Console.WriteLine("Number of campaigns found: {0}", page.totalNumEntries)
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to retrieve campaign(s).", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Get all campaigns using AWQL

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.Util.Reports.v201809
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example lists all campaigns using an AWQL query. See
    ''' https://developers.google.com/adwords/api/docs/guides/awql for AWQL
    ''' documentation. To add a campaign, run AddCampaign.vb.
    ''' </summary>
    Public Class GetCampaignsWithAwql
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New GetCampaignsWithAwql
            Console.WriteLine(codeExample.Description)
            Try
                codeExample.Run(New AdWordsUser)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return "This code example lists all campaigns using an AWQL query. See " &
                       "https://developers.google.com/adwords/api/docs/guides/awql for AWQL " &
                       "documentation. To add a campaign, run AddCampaign.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        Public Sub Run(ByVal user As AdWordsUser)
            Using campaignService As CampaignService = CType(
                user.GetService(
                    AdWordsService.v201809.CampaignService),
                CampaignService)

                ' Create the query.
                Dim query As SelectQuery = New SelectQueryBuilder() _
                        .Select(Campaign.Fields.Name, Campaign.Fields.Id, Campaign.Fields.Status) _
                        .OrderByAscending(Campaign.Fields.Name) _
                        .DefaultLimit() _
                        .Build()

                Dim page As New CampaignPage()
                Dim i As Integer = 0


                Try
                    Do
                        ' Get the campaigns.
                        page = campaignService.query(query)

                        ' Display the results.
                        If ((Not page Is Nothing) AndAlso (Not page.entries Is Nothing)) Then
                            For Each campaign As Campaign In page.entries
                                Console.WriteLine(
                                    "{0}) Campaign with id = '{1}', name = '{2}' and status = " &
                                    "'{3}' was found.", i, campaign.id, campaign.name,
                                    campaign.status)
                                i += 1
                            Next
                        End If
                        query.NextPage(page)
                    Loop While (query.HasNextPage(page))
                    Console.WriteLine("Number of campaigns found: {0}", page.totalNumEntries)
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to retrieve campaign(s).", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Get expanded text ads in an ad group

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example retrieves all expanded text ads given an existing ad
    ''' group. To add expanded text ads to an existing ad group, run
    ''' AddExpandedTextAds.vb.
    ''' </summary>
    Public Class GetExpandedTextAds
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New GetExpandedTextAds
            Console.WriteLine(codeExample.Description)
            Try
                Dim adGroupId As Long = Long.Parse("INSERT_ADGROUP_ID_HERE")
                codeExample.Run(New AdWordsUser, adGroupId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return "This code example retrieves all expanded text ads given an existing ad " &
                       "group. To add expanded text ads to an existing ad group, run " &
                       "AddExpandedTextAds.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adGroupId">Id of the ad group from which expanded text ads
        ''' are retrieved.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long)
            Using service As AdGroupAdService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupAdService),
                AdGroupAdService)

                ' Create a selector.
                Dim selector As New Selector

                selector.fields = New String() { _
                                                   ExpandedTextAd.Fields.Id,
                                                   AdGroupAd.Fields.Status,
                                                   ExpandedTextAd.Fields.HeadlinePart1,
                                                   ExpandedTextAd.Fields.HeadlinePart2,
                                                   ExpandedTextAd.Fields.Description
                                               }

                selector.ordering = New OrderBy() {OrderBy.Asc(TextAd.Fields.Id)}

                Dim fieldStatusStrings = New String() { _
                                                          AdGroupAdStatus.ENABLED.ToString(),
                                                          AdGroupAdStatus.PAUSED.ToString(),
                                                          AdGroupAdStatus.DISABLED.ToString()
                                                      }
                selector.predicates = New Predicate() { _
                                                          Predicate.Equals(
                                                              AdGroupAd.Fields.AdGroupId,
                                                              adGroupId),
                                                          Predicate.Equals("AdType",
                                                                           "EXPANDED_TEXT_AD"),
                                                          Predicate.In(AdGroupAd.Fields.Status,
                                                                       fieldStatusStrings)
                                                      }

                ' Select the selector paging.
                selector.paging = Paging.Default

                Dim page As New AdGroupAdPage

                Try
                    Do
                        ' Get the expanded text ads.
                        page = service.get(selector)

                        ' Display the results.
                        If ((Not page Is Nothing) AndAlso (Not page.entries Is Nothing)) Then
                            Dim i As Integer = selector.paging.startIndex

                            For Each adGroupAd As AdGroupAd In page.entries
                                Dim expandedTextAd As ExpandedTextAd = CType(adGroupAd.ad,
                                                                             ExpandedTextAd)
                                Console.WriteLine(
                                    "{0} : Expanded text ad with ID '{1}', headline '{2} - {3}' " &
                                    "and description '{4} was found.", i + 1, expandedTextAd.id,
                                    expandedTextAd.headlinePart1, expandedTextAd.headlinePart2,
                                    expandedTextAd.description)
                            Next
                            i += 1
                        End If
                        selector.paging.IncreaseOffset()
                    Loop While (selector.paging.startIndex < page.totalNumEntries)
                    Console.WriteLine("Number of expanded text ads found: {0}",
                                      page.totalNumEntries)
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to get expanded text ads.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Get keywords in an ad group

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example gets all keywords in an ad group. To add keywords, run
    ''' AddKeywords.vb.
    ''' </summary>
    Public Class GetKeywords
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New GetKeywords
            Console.WriteLine(codeExample.Description)
            Try
                Dim adGroupId As Long = Long.Parse("INSERT_ADGROUP_ID_HERE")
                codeExample.Run(New AdWordsUser, adGroupId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return "This code example gets all keywords in an ad group. To add keywords, run " &
                       "AddKeywords.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adGroupId">ID of the ad group from which keywords are
        ''' retrieved.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long)
            Using adGroupCriterionService As AdGroupCriterionService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupCriterionService),
                AdGroupCriterionService)

                ' Create a selector.
                Dim selector As New Selector
                selector.fields = New String() { _
                                                   Keyword.Fields.Id,
                                                   Keyword.Fields.KeywordMatchType,
                                                   Keyword.Fields.KeywordText,
                                                   Keyword.Fields.CriteriaType
                                               }

                ' Select only keywords.
                Dim criteriaPredicate As New Predicate
                criteriaPredicate.field = "CriteriaType"
                criteriaPredicate.operator = PredicateOperator.IN
                criteriaPredicate.values = New String() {"KEYWORD"}

                ' Restrict search to an ad group.
                Dim adGroupPredicate As New Predicate
                adGroupPredicate.field = "AdGroupId"
                adGroupPredicate.operator = PredicateOperator.EQUALS
                adGroupPredicate.values = New String() {adGroupId.ToString()}

                selector.predicates = New Predicate() { _
                                                          Predicate.In(Keyword.Fields.CriteriaType,
                                                                       New String() {"KEYWORD"}),
                                                          Predicate.Equals(
                                                              AdGroupCriterion.Fields.AdGroupId,
                                                              adGroupId)
                                                      }
                selector.ordering = New OrderBy() {OrderBy.Asc(Keyword.Fields.KeywordText)}
                selector.paging = Paging.Default

                Dim page As New AdGroupCriterionPage

                Try
                    Do
                        ' Get the keywords.
                        page = adGroupCriterionService.get(selector)

                        ' Display the results.
                        If ((Not page Is Nothing) AndAlso (Not page.entries Is Nothing)) Then
                            Dim i As Integer = selector.paging.startIndex

                            For Each adGroupCriterion As AdGroupCriterion In page.entries
                                Dim keyword As Keyword = CType(adGroupCriterion.criterion, Keyword)

                                Console.WriteLine(
                                    "{0}) Keyword with text '{1}', match type '{2}', criteria " &
                                    "type '{3}', and ID {4} was found.", i + 1, keyword.text,
                                    keyword.matchType,
                                    keyword.type, keyword.id)
                                i += 1
                            Next
                        End If
                        selector.paging.IncreaseOffset()
                    Loop While (selector.paging.startIndex < page.totalNumEntries)
                    Console.WriteLine("Number of keywords found: {0}", page.totalNumEntries)
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to retrieve keywords.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Pause an ad

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example pauses a given ad. To list all ads, run GetExpandedTextAds.vb.
    ''' </summary>
    Public Class PauseAd
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New PauseAd
            Console.WriteLine(codeExample.Description)
            Try
                Dim adGroupId As Long = Long.Parse("INSERT_ADGROUP_ID_HERE")
                Dim adId As Long = Long.Parse("INSERT_AD_ID_HERE")
                codeExample.Run(New AdWordsUser, adGroupId, adId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return "This code example pauses a given ad. To list all ads, run " &
                       "GetExpandedTextAds.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adGroupId">Id of the ad group that contains the ad.
        ''' </param>
        ''' <param name="adId">Id of the ad to be paused.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long, ByVal adId As Long)
            Using service As AdGroupAdService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupAdService),
                AdGroupAdService)

                Dim status As AdGroupAdStatus = AdGroupAdStatus.PAUSED

                ' Create the ad group ad.
                Dim adGroupAd As New AdGroupAd
                adGroupAd.status = status
                adGroupAd.adGroupId = adGroupId

                adGroupAd.ad = New Ad
                adGroupAd.ad.id = adId

                ' Create the operation.
                Dim adGroupAdOperation As New AdGroupAdOperation
                adGroupAdOperation.operator = [Operator].SET
                adGroupAdOperation.operand = adGroupAd

                Try
                    ' Update the ad.
                    Dim retVal As AdGroupAdReturnValue = service.mutate(
                        New AdGroupAdOperation() {adGroupAdOperation})

                    ' Display the results.
                    If ((Not retVal Is Nothing) AndAlso (Not retVal.value Is Nothing) AndAlso
                        (retVal.value.Length > 0)) Then
                        Dim pausedAdGroupAd As AdGroupAd = retVal.value(0)
                        Console.WriteLine("Ad with id ""{0}"" was paused.", pausedAdGroupAd.ad.id)
                    Else
                        Console.WriteLine("No ads were paused.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to pause ad.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Remove an ad

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example removes an ad using the 'REMOVE' operator. To list ads,
    ''' run GetTextAds.vb.
    ''' </summary>
    Public Class RemoveAd
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New RemoveAd
            Console.WriteLine(codeExample.Description)
            Try
                Dim adGroupId As Long = Long.Parse("INSERT_ADGROUP_ID_HERE")
                Dim adId As Long = Long.Parse("INSERT_AD_ID_HERE")
                codeExample.Run(New AdWordsUser, adGroupId, adId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return _
                    "This code example removes an ad using the 'REMOVE' operator. To list ads, " &
                    "run GetTextAds.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adGroupId">Id of the ad group that contains the ad.</param>
        ''' <param name="adId">Id of the ad being removed.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long, ByVal adId As Long)
            Using adGroupAdService As AdGroupAdService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupAdService),
                AdGroupAdService)

                ' Since we do not need to update any ad-specific fields, it is enough to
                ' create the base type.
                Dim ad As New Ad
                ad.id = adId

                ' Create the ad group ad.
                Dim adGroupAd As New AdGroupAd
                adGroupAd.adGroupId = adGroupId

                adGroupAd.ad = ad

                ' Create the operation.
                Dim operation As New AdGroupAdOperation
                operation.operand = adGroupAd
                operation.operator = [Operator].REMOVE

                Try
                    ' Remove the ad.
                    Dim retVal As AdGroupAdReturnValue = adGroupAdService.mutate(
                        New AdGroupAdOperation() {operation})

                    If ((Not retVal Is Nothing) AndAlso (Not retVal.value Is Nothing) AndAlso
                        (retVal.value.Length > 0)) Then
                        Dim removedAdGroupAd As AdGroupAd = retVal.value(0)
                        Console.WriteLine("Ad with id = ""{0}"" and type = ""{1}"" was removed.",
                                          removedAdGroupAd.ad.id, removedAdGroupAd.ad.AdType)
                    Else
                        Console.WriteLine("No ads were removed.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to remove ad.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Remove an ad group

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example removes an ad group by setting the status to 'REMOVED'.
    ''' To get ad groups, run GetAdGroups.vb.
    ''' </summary>
    Public Class RemoveAdGroup
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New RemoveAdGroup
            Console.WriteLine(codeExample.Description)
            Try
                Dim adGroupId As Long = Long.Parse("INSERT_ADGROUP_ID_HERE")
                codeExample.Run(New AdWordsUser, adGroupId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return _
                    "This code example removes an ad group by setting the status to 'REMOVED'. " &
                    "To get ad groups, run GetAdGroups.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adGroupId">Id of the ad group to be removed.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long)
            Using adGroupService As AdGroupService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupService),
                AdGroupService)

                ' Create ad group with REMOVED status.
                Dim adGroup As New AdGroup
                adGroup.id = adGroupId
                adGroup.status = AdGroupStatus.REMOVED

                ' Create the operation.
                Dim operation As New AdGroupOperation
                operation.operand = adGroup
                operation.operator = [Operator].SET

                Try
                    ' Remove the ad group.
                    Dim retVal As AdGroupReturnValue = adGroupService.mutate(
                        New AdGroupOperation() {operation})

                    ' Display the results.
                    If ((Not retVal Is Nothing) AndAlso (Not retVal.value Is Nothing) AndAlso
                        (retVal.value.Length > 0)) Then
                        Dim removedAdGroup As AdGroup = retVal.value(0)
                        Console.WriteLine(
                            "Ad group with id = ""{0}"" and name = ""{1}"" was removed.",
                            removedAdGroup.id, removedAdGroup.name)
                    Else
                        Console.WriteLine("No ad groups were removed.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to remove ad groups.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Remove a campaign

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example removes a campaign by setting the status to 'REMOVED'.
    ''' To get campaigns, run GetCampaigns.vb.
    ''' </summary>
    Public Class RemoveCampaign
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New RemoveCampaign
            Console.WriteLine(codeExample.Description)
            Try
                Dim campaignId As Long = Long.Parse("INSERT_CAMPAIGN_ID_HERE")
                codeExample.Run(New AdWordsUser, campaignId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return _
                    "This code example removes a campaign by setting the status to 'REMOVED'. To " &
                    "get campaigns, run GetCampaigns.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="campaignId">Id of the campaign to be removed.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal campaignId As Long)
            Using campaignService As CampaignService = CType(
                user.GetService(
                    AdWordsService.v201809.CampaignService),
                CampaignService)

                ' Create campaign with REMOVED status.
                Dim campaign As New Campaign
                campaign.id = campaignId
                campaign.status = CampaignStatus.REMOVED

                ' Create the operation.
                Dim operation As New CampaignOperation
                operation.operand = campaign
                operation.operator = [Operator].SET

                Try
                    ' Remove the campaign.
                    Dim retVal As CampaignReturnValue = campaignService.mutate(
                        New CampaignOperation() {operation})

                    ' Display the results.
                    If ((Not retVal Is Nothing) AndAlso (Not retVal.value Is Nothing) AndAlso
                        (retVal.value.Length > 0)) Then
                        Dim removedCampaign As Campaign = retVal.value(0)
                        Console.WriteLine(
                            "Campaign with id = ""{0}"" was renamed to ""{1}"" and removed.",
                            removedCampaign.id, removedCampaign.name)
                    Else
                        Console.WriteLine("No campaigns were removed.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to remove campaigns.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Remove a keyword

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example removes a keyword using the 'REMOVE' operator. To get
    ''' keywords, run GetKeywords.vb.
    ''' </summary>
    Public Class RemoveKeyword
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New RemoveKeyword
            Console.WriteLine(codeExample.Description)
            Try
                Dim adGroupId As Long = Long.Parse("INSERT_ADGROUP_ID_HERE")
                Dim keywordId As Long = Long.Parse("INSERT_KEYWORD_ID_HERE")
                codeExample.Run(New AdWordsUser, adGroupId, keywordId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return "This code example removes a keyword using the 'REMOVE' operator. To get " &
                       "keywords, run GetKeywords.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adGroupId">Id of the ad group that contains the keyword.
        ''' </param>
        ''' <param name="keywordId">Id of the keyword to be removed.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long, ByVal keywordId As Long)
            Using adGroupCriterionService As AdGroupCriterionService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupCriterionService),
                AdGroupCriterionService)

                ' Create base class criterion to avoid setting keyword-specific
                ' fields.
                Dim criterion As New Criterion
                criterion.id = keywordId

                ' Create the ad group criterion.
                Dim adGroupCriterion As New BiddableAdGroupCriterion
                adGroupCriterion.adGroupId = adGroupId
                adGroupCriterion.criterion = criterion

                ' Create the operation.
                Dim operation As New AdGroupCriterionOperation
                operation.operand = adGroupCriterion
                operation.operator = [Operator].REMOVE

                Try
                    ' Remove the keyword.
                    Dim retVal As AdGroupCriterionReturnValue = adGroupCriterionService.mutate(
                        New AdGroupCriterionOperation() {operation})

                    ' Display the results.
                    If ((Not retVal Is Nothing) AndAlso (Not retVal.value Is Nothing) AndAlso
                        (retVal.value.Length > 0)) Then
                        Dim removedKeyword As AdGroupCriterion = retVal.value(0)
                        Console.WriteLine(
                            "Keyword with ad group id = ""{0}"" and id = ""{1}"" was " &
                            "removed.", removedKeyword.adGroupId, removedKeyword.criterion.id)
                    Else
                        Console.WriteLine("No keywords were removed.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to remove keywords.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Update an ad group

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example illustrates how to update an ad group, setting its
    ''' status to 'PAUSED', and its CPC bid to a new value if specified.
    ''' To create an ad group, run AddAdGroup.vb.
    ''' </summary>
    Public Class UpdateAdGroup
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New UpdateAdGroup
            Console.WriteLine(codeExample.Description)
            Try
                Dim adGroupId As Long = Long.Parse("INSERT_ADGROUP_ID_HERE")
                Dim bidMicroAmount As Long? = Nothing

                ' Optional: Provide a cpc bid for the ad group, in micro amounts.
                Dim tempVal As Long = 0
                If Long.TryParse("INSERT_CPC_BID_IN_MICROS_HERE", tempVal) Then
                    bidMicroAmount = New Nullable(Of Long)(tempVal)
                End If

                codeExample.Run(New AdWordsUser, adGroupId, bidMicroAmount)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return _
                    "This code example illustrates how to update an ad group, setting its status " &
                    "to 'PAUSED', and its CPC bid to a new value if specified. To create an ad " &
                    "group, run AddAdGroup.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adGroupId">Id of the ad group to be updated.</param>
        ''' <param name="bidMicroAmount">The CPC bid amount in micros.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long,
                       ByVal bidMicroAmount As Long?)
            Using adGroupService As AdGroupService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupService),
                AdGroupService)

                ' Create an ad group with the specified ID.
                Dim adGroup As New AdGroup
                adGroup.id = adGroupId

                ' Pause the ad group.
                adGroup.status = AdGroupStatus.PAUSED

                ' Update the CPC bid if specified.
                If bidMicroAmount.HasValue() Then
                    Dim biddingStrategyConfiguration As New BiddingStrategyConfiguration()
                    Dim cpcBidMoney = New Money()
                    cpcBidMoney.microAmount = bidMicroAmount.Value
                    Dim cpcBid As New CpcBid()
                    cpcBid.bid = cpcBidMoney
                    biddingStrategyConfiguration.bids = New Bids() {cpcBid}
                    adGroup.biddingStrategyConfiguration = biddingStrategyConfiguration
                End If

                ' Create the operation.
                Dim operation As New AdGroupOperation
                operation.operator = [Operator].SET
                operation.operand = adGroup

                Try
                    ' Update the ad group.
                    Dim retVal As AdGroupReturnValue = adGroupService.mutate(
                        New AdGroupOperation() {operation})

                    ' Display the results.
                    If ((Not retVal Is Nothing) AndAlso (Not retVal.value Is Nothing) AndAlso
                        (retVal.value.Length > 0)) Then
                        Dim adGroupResult As AdGroup = retVal.value(0)
                        Dim bsConfig As BiddingStrategyConfiguration =
                                adGroupResult.biddingStrategyConfiguration

                        ' Find the CpcBid in the bidding strategy configuration's bids collection.
                        Dim cpcBidMicros As Long = 0L
                        If (Not bsConfig Is Nothing) AndAlso (Not bsConfig.bids Is Nothing) Then
                            For Each Bid As Bids In bsConfig.bids
                                If TypeOf Bid Is CpcBid Then
                                    cpcBidMicros = DirectCast(Bid, CpcBid).bid.microAmount
                                    Exit For
                                End If
                            Next
                        End If
                        Console.WriteLine(
                            "Ad group with ID {0} and name '{1}' updated to have status '{2}'" &
                            " and CPC bid {3}", adGroupResult.id, adGroupResult.name,
                            adGroupResult.status, cpcBidMicros)
                    Else
                        Console.WriteLine("No ad groups were updated.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to update ad groups.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Update a campaign

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example updates a campaign. To get campaigns, run
    ''' GetCampaigns.vb.
    ''' </summary>
    Public Class UpdateCampaign
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New UpdateCampaign
            Console.WriteLine(codeExample.Description)
            Try
                Dim campaignId As Long = Long.Parse("INSERT_CAMPAIGN_ID_HERE")
                codeExample.Run(New AdWordsUser, campaignId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return _
                    "This code example updates a campaign. To get campaigns, run GetCampaigns.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="campaignId">Id of the campaign to be updated.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal campaignId As Long)
            Using campaignService As CampaignService = CType(
                user.GetService(
                    AdWordsService.v201809.CampaignService),
                CampaignService)

                ' Create campaign with updated budget.
                Dim campaign As New Campaign
                campaign.id = campaignId
                campaign.status = CampaignStatus.PAUSED

                ' Create the operations.
                Dim operation As New CampaignOperation
                operation.operator = [Operator].SET
                operation.operand = campaign

                Try
                    ' Update the campaign.
                    Dim retVal As CampaignReturnValue = campaignService.mutate(
                        New CampaignOperation() {operation})

                    ' Display the results.
                    If ((Not retVal Is Nothing) AndAlso (Not retVal.value Is Nothing) AndAlso
                        (retVal.value.Length > 0)) Then
                        Dim updatedCampaign As Campaign = retVal.value(0)
                        Console.WriteLine("Campaign with name = '{0}' and id = '{1}' was updated.",
                                          updatedCampaign.name, updatedCampaign.id)
                    Else
                        Console.WriteLine("No campaigns were updated.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to update campaigns.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Update an expanded text ad

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example updates an expanded text ad. To get expanded text ads,
    ''' run GetExpandedTextAds.vb.
    ''' </summary>
    Public Class UpdateExpandedTextAd
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New UpdateExpandedTextAd
            Console.WriteLine(codeExample.Description)
            Try
                Dim adId As Long = Long.Parse("INSERT_AD_ID_HERE")
                codeExample.Run(New AdWordsUser, adId)

            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return _
                    "This code example updates an expanded text ad. To get expanded text ads, " +
                    "run GetExpandedTextAds.cs."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adId">Id of the ad to be updated.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adId As Long)
            Using service As AdService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupAdService),
                AdService)

                ' Create an expanded text ad using the provided ad ID.
                Dim expandedTextAd As New ExpandedTextAd()
                expandedTextAd.id = adId

                ' Update some properties of the expanded text ad.
                expandedTextAd.headlinePart1 = "Cruise to Pluto #" +
                                               ExampleUtilities.GetShortRandomString()
                expandedTextAd.headlinePart2 = "Tickets on sale now"
                expandedTextAd.description = "Best space cruise ever."
                expandedTextAd.finalUrls = New String() {"http://www.example.com/"}
                expandedTextAd.finalMobileUrls = New String() {"http://www.example.com/mobile"}

                ' Create ad group ad operation And add it to the list.
                Dim operation As New AdOperation
                operation.operator = [Operator].SET
                operation.operand = expandedTextAd

                Try
                    ' Update the ad on the server.
                    Dim result As AdReturnValue = service.mutate(New AdOperation() {operation})
                    Dim updatedAd As ExpandedTextAd = CType(result.value(0), ExpandedTextAd)

                    ' Print out some information.
                    Console.WriteLine("Expanded text ad with ID {0} was updated.", updatedAd.id)
                    Console.WriteLine(
                        "Headline part 1: {0}\nHeadline part 2: {1}\nDescription: {2}" +
                        "\nFinal URL: {3}\nFinal mobile URL: {4}",
                        updatedAd.headlinePart1, updatedAd.headlinePart2, updatedAd.description,
                        updatedAd.finalUrls(0), updatedAd.finalMobileUrls(0))
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to update expanded text ad.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

Update a keyword

' Copyright 2018 Google LLC
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809

Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
    ''' <summary>
    ''' This code example updates the bid of a keyword. To get keyword, run
    ''' GetKeywords.vb.
    ''' </summary>
    Public Class UpdateKeyword
        Inherits ExampleBase

        ''' <summary>
        ''' Main method, to run this code example as a standalone application.
        ''' </summary>
        ''' <param name="args">The command line arguments.</param>
        Public Shared Sub Main(ByVal args As String())
            Dim codeExample As New UpdateKeyword
            Console.WriteLine(codeExample.Description)
            Try
                Dim adGroupId As Long = Long.Parse("INSERT_ADGROUP_ID_HERE")
                Dim keywordId As Long = Long.Parse("INSERT_KEYWORD_ID_HERE")
                codeExample.Run(New AdWordsUser, adGroupId, keywordId)
            Catch e As Exception
                Console.WriteLine("An exception occurred while running this code example. {0}",
                                  ExampleUtilities.FormatException(e))
            End Try
        End Sub

        ''' <summary>
        ''' Returns a description about the code example.
        ''' </summary>
        Public Overrides ReadOnly Property Description() As String
            Get
                Return "This code example updates the bid of a keyword. To get keyword, run " +
                       "GetKeywords.vb."
            End Get
        End Property

        ''' <summary>
        ''' Runs the code example.
        ''' </summary>
        ''' <param name="user">The AdWords user.</param>
        ''' <param name="adGroupId">Id of the ad group that contains the keyword.
        ''' </param>
        ''' <param name="keywordId">Id of the keyword to be updated.</param>
        Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long, ByVal keywordId As Long)
            Using adGroupCriterionService As AdGroupCriterionService = CType(
                user.GetService(
                    AdWordsService.v201809.AdGroupCriterionService),
                AdGroupCriterionService)

                ' Since we are not updating any keyword-specific fields, it is enough to
                ' create a criterion object.
                Dim criterion As New Criterion
                criterion.id = keywordId

                ' Create ad group criterion.
                Dim biddableAdGroupCriterion As New BiddableAdGroupCriterion
                biddableAdGroupCriterion.adGroupId = adGroupId
                biddableAdGroupCriterion.criterion = criterion

                ' Create the bids.
                Dim biddingConfig As New BiddingStrategyConfiguration()
                Dim cpcBid As New CpcBid()
                cpcBid.bid = New Money()
                cpcBid.bid.microAmount = 1000000
                biddingConfig.bids = New Bids() {cpcBid}

                biddableAdGroupCriterion.biddingStrategyConfiguration = biddingConfig

                ' Create the operation.
                Dim operation As New AdGroupCriterionOperation
                operation.operator = [Operator].SET
                operation.operand = biddableAdGroupCriterion

                Try
                    ' Update the keyword.
                    Dim retVal As AdGroupCriterionReturnValue = adGroupCriterionService.mutate(
                        New AdGroupCriterionOperation() {operation})

                    ' Display the results.
                    If ((Not retVal Is Nothing) AndAlso (Not retVal.value Is Nothing) AndAlso
                        (retVal.value.Length > 0)) Then
                        Dim adGroupCriterion As BiddableAdGroupCriterion =
                                CType(retVal.value(0), BiddableAdGroupCriterion)
                        Dim bidAmount As Long = 0L
                        For Each bids As Bids In adGroupCriterion.biddingStrategyConfiguration.bids
                            If TypeOf bids Is CpcBid Then
                                bidAmount = TryCast(bids, CpcBid).bid.microAmount
                            End If
                        Next

                        Console.WriteLine(
                            "Keyword with ad group id = '{0}', id = '{1}' was updated with " &
                            "bid amount = '{2}' micros.", adGroupCriterion.adGroupId,
                            adGroupCriterion.criterion.id, bidAmount)
                    Else
                        Console.WriteLine("No keyword was updated.")
                    End If
                Catch e As Exception
                    Throw New System.ApplicationException("Failed to update keyword.", e)
                End Try
            End Using
        End Sub
    End Class
End Namespace

フィードバックを送信...

ご不明な点がありましたら、Google のサポートページをご覧ください。