AuthorizationError USER_PERMISSION_DENIED

204 views
Skip to first unread message

Chad Ruff

unread,
Jul 22, 2014, 7:02:46 AM7/22/14
to adwor...@googlegroups.com
Hi ,

I have adwords google api asp.net code sample googleads-dotnet-lib-master.zip

I have also generated the OAuth2RefreshToken using the OAuthTokenGenerator project

i have made changes to the app.config file 
 <add key="UserAgent" value="GoogleAdwordsTest"/>
 <add key="DeveloperToken" value="DeveloperToken"/>
  <add key="ClientCustomerId" value="123-456-7890"/>
  <add key="AuthorizationMethod" value="OAuth2" />
  <add key="Email" value="te...@gmail.com"/>
  <add key="Password" value="Password"/>
  <add key="OAuth2ClientId" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com" />
 <add key="OAuth2ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
 <add key="OAuth2Mode" value="APPLICATION" />

i am running the Google.Api.Adwords.Examples.VB.v201406.GetCampaigns sample from 

Adwords.Examples.VB Project v201406-->BasicOperations--> GetCampaigns.vb class

i have just added these two lines

  Public Sub Run(ByVal user As AdWordsUser)
      ' Get the CampaignService.
      Dim campaignService As CampaignService = user.GetService( _
          AdWordsService.v201406.CampaignService)

            Dim config As AdWordsAppConfig = DirectCast(user.Config, AdWordsAppConfig)
            config.ClientCustomerId = "987-654-4321".ToString().Replace("-", "")
            config.DeveloperToken = "DeveloperToken"

      Dim selector As New Selector
      selector.fields = New String() {"Id", "Name", "Status"}

      ' Set the selector paging.
      selector.paging = New Paging

      Dim offset As Integer = 0
      Dim pageSize As Integer = 500

      Dim page As New CampaignPage

      Try
        Do
          selector.paging.startIndex = offset
          selector.paging.numberResults = pageSize

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

I am getting  this error [AuthorizationError.USER_PERMISSION_DENIED @ ; trigger:'<null>'] on the above line

Chad Ruff

unread,
Jul 22, 2014, 11:13:48 AM7/22/14
to adwor...@googlegroups.com
Hi,

From the below Code i have removed the ClientCustomerId from App.config

Now it works and does not give any error 
but i don't get any campaign  records for my clients 

Now i am just assigning the clientCustomerID  as stated below

            Dim config As AdWordsAppConfig = DirectCast(user.Config, AdWordsAppConfig)
            config.ClientCustomerId = "987-654-4321".ToString().Replace("-", "")
            config.DeveloperToken = "DeveloperToken"

here i am just assigning the client's CustomerID but it is returning me zero records

but actually campaigns do exist for this client

Can you tell me what i am doing wrong 

or am i missing anything

Josh Radcliff (AdWords API Team)

unread,
Jul 22, 2014, 4:36:15 PM7/22/14
to adwor...@googlegroups.com
Hi,

Could you provide the following information?

1. Were you logged in under a) an MCC account or b) an AdWords account when you generated the refresh token in your config?
2. Is the client customer ID you are using in the code snippet below for an MCC account or an AdWords account?

I ask these questions because if you do not specify a client customer ID in your request then AdWords will infer the customer ID to use from the credentials on the request. Therefore, if the credentials are from an MCC account then you'll get back zero campaigns because an MCC account does not have any campaigns of its own.

Thanks,
Josh, AdWords API Team

Chad Ruff

unread,
Jul 23, 2014, 6:38:40 AM7/23/14
to adwor...@googlegroups.com
Hi ,

1. I had  logged into my  MCC account  account when i  generated the refresh token in my config.
2. The  client customer ID that i am using in my code snippet below is for an AdWords account
 
  config.ClientCustomerId = "449-909-2808".ToString().Replace("-", "")

Thanks and Regards



On Tuesday, July 22, 2014 4:32:46 PM UTC+5:30, Chad Ruff wrote:

Josh Radcliff (AdWords API Team)

unread,
Jul 23, 2014, 10:19:35 AM7/23/14
to adwor...@googlegroups.com
Hi,

You are setting the values on the config after you call the AdWordsUser constructor. Since the values from the config are set in the AdWordsUser's base class constructor, your changes to the config after the constructor call will have no effect on the AdWordsUser object.

Any one of the following would fix this issue:
  1. Modify the config before creating your AdWordsUser
  2. Set the ClientCustomerId in your config XML to the correct customer ID
  3. Set the clientCustomerId on the request header directly via: campaignService.RequestHeader.clientCustomerId = "449-909-2808"
Please give one of those a try and let me know if you still run into problems.

Cheers,
Josh, AdWords API Team

Chad Ruff

unread,
Jul 24, 2014, 5:14:41 AM7/24/14
to adwor...@googlegroups.com
Hi, Josh
  
   I have Top level MCC which has a different Customer ID  and many client Adwords Accounts under this mcc account
   My App.cofig does not have any settings i have commented them all
   
  i have created a getUser function Which assign the config values 
 
This is Code file for GetCampaigns.vb from Adwords  Project Code samples for Dot net
   
   googleads-dotnet-lib-master\examples\AdWords\Vb\v201406\BasicOperations

 I am using this v201406

Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201406

Imports System
Imports System.Collections.Generic
Imports System.IO

Namespace Google.Api.Ads.AdWords.Examples.VB.v201406
  ''' <summary>
  ''' This code example lists all campaigns. To add a campaign, run
  ''' AddCampaign.vb.
  '''
  ''' Tags: CampaignService.get
  ''' </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()
      Catch ex As Exception
        Console.WriteLine("An exception occurred while running this code example. {0}", _
            ExampleUtilities.FormatException(ex))
      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()
            Dim user As AdWordsUser
            user = getUser()
            ' Get the CampaignService.
            Dim campaignService As CampaignService = user.GetService( _
                AdWordsService.v201406.CampaignService)


            ' Create the selector.
            Dim selector As New Selector
            selector.fields = New String() {"Id", "Name", "Status"}

            ' Set the selector paging.
            selector.paging = New Paging

            Dim offset As Integer = 0
            Dim pageSize As Integer = 500

            Dim page As New CampaignPage

            Try
                Do
                    TryCast(user.Config, AdWordsAppConfig).ClientCustomerId = "746-686-2521"
                   ' This is my Clients ClientCustomerId  which i have verified but i do  not get any records for it 
                   ' I Get 0  zero where as Campaigns Exist for this Client which i have verified
                    selector.paging.startIndex = offset
                    selector.paging.numberResults = pageSize

                    page = campaignService.get(selector)

                    ' Display the results.
                    If ((Not page Is Nothing) AndAlso (Not page.entries Is Nothing)) Then
                        Dim i As Integer = offset
                        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
                    offset = offset + pageSize
                Loop While (offset < page.totalNumEntries)
                Console.WriteLine("Number of campaigns found: {0}", page.totalNumEntries)
            Catch ex As Exception
                Throw New System.ApplicationException("Failed to retrieve campaign(s).", ex)
            End Try
        End Sub

        Public Function getUser() As AdWordsUser
         'All this have correct values Which i have verified
      Try
                Dim user As New AdWordsUser()
                Dim config As AdWordsAppConfig = DirectCast(user.Config, AdWordsAppConfig)
                 config.AuthorizationMethod = AdWordsAuthorizationMethod.OAuth2
                config.OAuth2ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxxx"
                config.OAuth2ClientId = "xxxxxxxxxxxxxxxxx-xxxxx.apps.googleusercontent.com"
                config.OAuth2RefreshToken = "xxxxxxxxxxxxxxxxxx"
                config.DeveloperToken = "xxxxxxxxxxxxxxxxxxx"

                Return user

            Catch ex As Exception
                Return Nothing
            End Try
        End Function
  End Class
End Namespace

Chad Ruff

unread,
Jul 24, 2014, 6:00:06 AM7/24/14
to adwor...@googlegroups.com
Hi Josh,

Please find attached request_info.log and soap_xml.log 

Thanks
request_info.log
soap_xml.log

Josh Radcliff (AdWords API Team)

unread,
Jul 24, 2014, 11:39:50 AM7/24/14
to adwor...@googlegroups.com
Hi,

As I mentioned in my previous post, setting the clientCustomerId on the AdWordsAppConfig object after you create your AdWordsUser will not set the clientCustomerId for requests made by that user. Please try one of the three options I mentioned in that post and confirm that the clientCustomerId SOAP header appears in your request.

Cheers,
Josh, AdWords API Team

Chad Ruff

unread,
Jul 25, 2014, 8:26:40 AM7/25/14
to adwor...@googlegroups.com
Hi Josh,

  I have Top level MCC which has a different Customer ID  and many client Adwords Accounts under this mcc account
   My App.cofig does not have any settings i have commented them all
   
  i have created a getUser function Which assign the config values 
 
This is Code file for GetCampaigns.vb from Adwords  Project Code samples for Dot net
   
   googleads-dotnet-lib-master\examples\AdWords\Vb\v201406\BasicOperations

 I am using this v201406

In  have changed my previous code

My Modified Code is as below

Now the ClientCustomerID is being set you can see in attached log files

 But now  i  am getting an error  as follows [AuthorizationError.USER_PERMISSION_DENIED @ ; trigger:'<null>']

I have about 28 clients i have tried with all the customerids for all the 28 i get this same error

Do you need more information which i can provide so that we can resolve this 

Thanks and Regards


                config.ClientCustomerId = "746-686-2521"
request_info.log
soap_xml.log

Josh Radcliff (AdWords API Team)

unread,
Jul 25, 2014, 11:34:16 AM7/25/14
to adwor...@googlegroups.com
Hi Chad,

That error indicates that the user you were logged in as when you went through the OAuth2 flow that generated the refresh token does not have access to the account specified in the clientCustomerId header.

When going through the OAuth2 flow to generate the refresh token, please make sure you are logged in as the proper Google account (usually an MCC that is linked to the client account). It may help to first log out of all of your Google accounts in your browser, restart your browser, and then navigate to the URL generated when you run the OAuth2 Token Generator.

Thanks,
Josh, AdWords API Team

Chad Ruff

unread,
Jul 28, 2014, 11:48:32 AM7/28/14
to adwor...@googlegroups.com
Hi Josh,

First of all thanks a lot for the update !!

Yes u were right it was a wrong google id that was used whille generating the token

I regenerated the token using the correct login details and i got the campaign details

now i am using a function to get the stats information 


   Public Function updateStats(ByVal SearchEngineCampaignObj As SearchEngineCampaign, ByVal MarketingTouchPointObj As MarketingTouchPoint) As Boolean
            Dim user As AdWordsUser
            user = getUser()

            If user Is Nothing Then
                Return False
            End If

   

            Try
                adGroupServiceObj = user.GetService(AdWordsService.v201406.AdGroupService)
            Catch ex As Exception
 
            End Try

            Dim CampaignID As Long

            Dim page As New AdGroupPage
            Dim secsObj As New SearchEngineCampaignStats   
            Dim dateRangeObj As DateRange

            Try
                CampaignID = CLng(ID)
            Catch ex As Exception
                Return False
            End Try

            Dim selector As New Selector
            selector.fields = New String() {"Id", "Name", "Status", "Impressions", "Cost", "Ctr", "AveragePosition", "Conversions", "Clicks"} ', "ConversionRate"}

            Dim orderByName As New OrderBy()
            orderByName.field = "Name"
            orderByName.sortOrder = SortOrder.ASCENDING
            selector.ordering = New OrderBy() {orderByName}

            ' Create the filters.
            Dim predicate As New Predicate
            predicate.field = "CampaignId"
            predicate.operator = PredicateOperator.IN
            predicate.values = New String() {CampaignID.ToString}


            selector.paging = New Paging()
            selector.paging.startIndex = 0
            selector.paging.numberResults = 500

            dateRangeObj = New DateRange()
            dateRangeObj.min =StartDate.ToString("yyyyMMdd")
            dateRangeObj.max = EndDate.ToString("yyyyMMdd")
            selector.dateRange = dateRangeObj

            selector.predicates = New Predicate() {predicate}

            Try
                page = adGroupServiceObj.get(selector)
            Catch ex As Exception
                Return False
            End Try

            If page Is Nothing Then
                Return False
            End If

            Try
                If page.entries Is Nothing Then
                    Return False
                End If
                If page.entries.Length = 0 Then
                    Return False
                End If
            Catch ex As Exception
                Return False
            End Try


            'For Each AdGroupObj As Google.Api.Ads.AdWords.v201406.AdGroup In page.entries

               i am getting compilation error for these lines 
                  AdGroupObj.stats.averagePosition
                  AdGroupObj.stats.clicks
                  AdGroupObj.stats.conversions
                  AdGroupObj.stats.cost.microAmount
                  AdGroupObj.stats.impressions
                 plz let me know how can i get this information of Adgroup  stats 
             Next  
        End Function

thanks and regards
Altaf


Josh Radcliff (AdWords API Team)

unread,
Jul 28, 2014, 12:22:06 PM7/28/14
to adwor...@googlegroups.com
Hi Altaf,

Stats and performance information is available through reports. The complete list of reports is here. You may want to check out our Reporting Basics guide as well as the reporting examples in the .NET client library.
Reply all
Reply to author
Forward
0 new messages