Get Campaigns in Visual Basic

The following example shows how to get campaigns within an account using the Campaign Management GetCampaignsByAccountId service operation.

This example has been developed and run within the environment described in Getting Started Using C# and Visual Basic with Bing Ads Services.

System_CLiX_note Note

This example uses the UserName and Password elements for authentication. For Managing User Authentication with OAuth, replace the UserName and Password elements with the AuthenticationToken, which is your OAuth access token.

Sub GetCampaigns( _
    ByRef username As String, _
    ByRef devtoken As String, _
    ByRef password As String, _
    ByRef accountid As Integer)
        ' Define the variables to use in this application.
        Dim svcCampMgt As CampaignManagementServiceClient
        Dim getCampaignsRequest As GetCampaignsByAccountIdRequest
        Dim getCampaignsResponse As GetCampaignsByAccountIdResponse

        ' Create an instance of the CampaignManagement Web service.
        svcCampMgt = New CampaignManagementServiceClient

        ' Call the GetCampaignsByAccountIdRequest service operaton to get the 
        ' campaigns.
        getCampaignsRequest = New GetCampaignsByAccountIdRequest(Nothing, accountid, Nothing, devtoken, password, username, accountid)

        getCampaignsResponse = _

        Console.WriteLine( _
            "Found {0} Campaigns, Tracking #: {1}", _
            getCampaignsResponse.Campaigns.Length, _

        For Each c As Campaign In getCampaignsResponse.Campaigns
            Console.WriteLine("Name         : " + c.Name)
            Console.WriteLine("Description  : " + c.Description)
            Console.WriteLine("Monthy Budget: " + c.MonthlyBudget.ToString())
            Console.WriteLine("Budget Type  : " + c.BudgetType.ToString())

    Catch fault As FaultException(Of ApiFaultDetail)
        Dim detail As ApiFaultDetail = fault.Detail

        ' Display any service operation error information.
        For Each opError As OperationError In detail.OperationErrors
            Console.Write("Operation error")
            Console.WriteLine( _
                " '{0}' ({1}) encountered.", _
                opError.Message, _

    Catch e As Exception
        ' Add your additional exception-handling code here.
        ' Capture exceptions on the client that are unrelated to
        ' the Bing Ads API. An example would be an
        ' out-of-memory condition on the client.
        Console.WriteLine("Error '{0}' encountered.", e.Message)
    End Try
End Sub

Community Additions