Hello AK,

How do you obtain your access and refresh tokens? Do you have AdWords scope 
included in the request?

Is the login used for OAuth2 flow allowed to access the MCC account you are 
trying to query?


-Danial, AdWords API Team.


On Friday, October 4, 2013 6:00:42 AM UTC+4, akinye...@centralr.co.nz wrote:
>
>
> Hi there,
> I am trying to create an adword account via the API. But any time I try to 
> mutate the ADD operation I keep getting "NOT_AUTHORIZED" error.
>
> Below is the code snippet:
>
>   AdWordsUser user = new AdWordsUser();
>         gsoAuth2TokenGenerator gsTkGen = new gsoAuth2TokenGenerator();
>
>
>         void InitConfig()
>         {
>             try
>             {
>                 //Config config Settings
>                 AdWordsAppConfig config = (AdWordsAppConfig)user.Config;
>                 config.DeveloperToken = oAuthDeveloperToken;
>                 config.AuthorizationMethod = 
> AdWordsAuthorizationMethod.OAuth2;
>                 config.ClientCustomerId = AccountCID;
>                 config.OAuth2PrnEmail = OAuth2PrnEmail;
>                 config.Email = email;
>                 config.OAuth2ClientId = oAuthClientID;
>                 config.OAuth2ClientSecret = oAuthClientsecret;
>                 config.OAuth2RedirectUri = oAuthRedirectURIs;
>                 config.OAuth2Scope = oAuthScope;
>                 config.Password = oAuthPassword;
>                 config.UserAgent = UserAgent;
>                 config.OAuth2Mode = 
> Google.Api.Ads.Common.Lib.OAuth2Flow.APPLICATION;
>                 config.AuthToken = AuthCode;
>                 config.OAuth2AccessToken = AccessToken;
>                 config.OAuth2RefreshToken = RefreshToken;
>
>                 if (AccessToken == null || RefreshToken == null)//Get 
> oAuth2 Token
>                 {
>                     var aToken = "";
>                     var rToken = "";
>
>                     //
>                     gsTkGen.GetTokens(oAuthClientID, oAuthClientsecret, 
> AuthCode, out aToken, out rToken);
>
>                     AccessToken = aToken;
>                     RefreshToken = rToken;
>                     // config.AuthToken = aToken;
>                     config.OAuth2AccessToken = aToken;
>                     config.OAuth2RefreshToken = rToken;
>                     // Refresh Access Token
>                     AccessToken = gsTkGen.GetAccessToken(oAuthClientID, 
> oAuthClientsecret, RefreshToken);
>                     
>                 }
>             }
>             catch (Exception)
>             {
>
>                 throw;
>             }
>         }
>
>         public string  CreateAccount()
>         {
>             try 
>         {
>                 InitConfig();
>                 // Get the ManagedCustomerService.
>                 ManagedCustomerService managedCustomerService = 
> (ManagedCustomerService)user.GetService(AdWordsService.v201306.ManagedCustomerService);
>                 // Create account.
>                 ManagedCustomer customer = new ManagedCustomer();
>                 customer.name = accountName;
>                 customer.currencyCode = accountCurrencyCode;
>                 customer.dateTimeZone = accountDateTimeZone;
>
>                 // Create operations.
>                 ManagedCustomerOperation operation = new 
> ManagedCustomerOperation();
>                 operation.operand = customer;
>                 operation.@operator = Operator.ADD;
>                 try
>                 {
>                     ManagedCustomerOperation[] operations = new 
> ManagedCustomerOperation[] { operation };
>                     // Add account.
>                     
>                   //  ManagedCustomerService managedCustomerService = 
> (ManagedCustomerService)user.GetService(AdWordsService.v201306.ManagedCustomerService);
>                     ManagedCustomerReturnValue result = 
> managedCustomerService.mutate(operations);
>
>                     // Display accounts.
>                     if (result.value != null && result.value.Length > 0)
>                     {
>                         ManagedCustomer customerResult = result.value[0];
>                         return "Account with customer ID " + 
> customerResult.customerId +" was created.";
>                     }
>                     else
>                     {
>                         return "No accounts were created.";
>                     } 
>                 }
>                 catch (Exception ex)
>                 {
>                     return "An Error Occurred: " + ex.Message;
>                 }
>         }
>         catch (Exception)
>         {
>
>                throw;
>         }
>        }
>
> Just a note: When we try other services like creating a campaign/Budget it 
> works fine.
>
> Regards,
> AK
>
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to