Anash,
Again thank you for your quick response. I am building a web application 
that when new items are added to our system we can potentially 
automatically add a new Campaign to the our AdWords account and then 
subsequently new AdGroups, Ads and Keywords. I am at the early stages 
really learning the capabilities of the API and I am having a few problems 
getting going. I downloaded the the .Net client library from here 
http://code.google.com/p/google-api-adwords-dotnet/ and I am using that as 
the basis of starting my own proof of concept project. Mainly my issues are 
compounded by the fact that all the examples I can find are a mix of 
different versions and so I am a little unclear on how to get going.

I think what I really need help with is how to get the AdWordsUser 
authenticated in a way that I can the access the API from then on with no 
challenge. I have no requirement to use OAuth as this will be an internal 
service using just our company AdWords account.

What I have so far is based on a combination of this Java 
example http://code.google.com/apis/adwords/docs/first-request.html and 
this article you 
wrote 
http://code.google.com/p/google-api-adwords-dotnet/wiki/HowToUseAdWordsUser

Here is my code:-

 public ActionResult Create()
{
var headers = new Dictionary<string, string>
               {
               {"CompanyName", "MyCompany.com"},
{"Email", "[email protected]"},
{"Password", "password"},
{"DeveloperToken", " myemail @gmail.com++USD"}
               };
var user = new AdWordsUser(headers);
var service = 
(CampaignService)user.GetService(AdWordsService.v201109.CampaignService, 
"https://sandbox.google.com";);
var budget = new Budget
 {
 period = BudgetBudgetPeriod.DAILY,
 amount = new Money(),
 deliveryMethod = BudgetBudgetDeliveryMethod.STANDARD
 };

var campaign = new Campaign
   {
   name = "Simon Campaign",
   status = CampaignStatus.PAUSED,
   biddingStrategy = new ManualCPC(),
   budget = budget
   };
var operation = new CampaignOperation {operand = campaign, @operator = 
Operator.ADD};
var operations = new[] { operation };
var result = service.mutate(operations);

return View();

This is an ASP.NET MVC 3 web application, when executing the code above I 
get an AuthTokenException. When I dig into the error it is because I am 
getting an System.Net.WebException {"The remote server returned an error: 
(403) Forbidden."}. I get exactly the same response when I remove the 
second argument from the GetService call on AdWordsUser.

If you could point me in the right direction I would be eternally grateful.

On Thursday, 29 March 2012 12:20:14 UTC+1, Anash P. Oommen wrote:
>
> Hi Simon,
>
> AFAIK, OAuth doesn't present a Captcha challenge, ClientLogin API does. 
> Sounds like a misconfiguration to me. OAuth 1.0a access tokens don't 
> expire, so you need to get the user to enter the credentials once to 
> generate an accessToken, save it, and then keep reusing it for future 
> requests. The other option is to link the client account under your MCC, 
> and use your credentials to generate AuthTokens. That way, you won't have 
> to ask for your client's credentials at all, but the linking process is 
> manual.
>
> Could you provide some more details of your application? E.g. is it a web 
> application?
>
> Cheers,
> Anash P. Oommen,
> AdWords API Advisor.
>
>
>
> On Thursday, 29 March 2012 16:31:31 UTC+5:30, baynezy wrote:
>>
>> Anash,
>> Thanks very much for your help on this. I think I have gone down the
>> wrong path here. The OAuth version of the API presents me with a
>> CAPTCH challenge that I need to forward to the user. However, I am not
>> creating a client application for users to manage their AdWords
>> accounts where this process makes perfect sense as I would not want to
>> store their account credentials. However, I am building an integration
>> with my application so I can programmatically create campaigns,
>> adgroups, etc. and this CAPTCHA challenge makes this not feasible as
>> this will not be in response to a user action but an automated
>> process. Is there a way to interact with the API where I can use my
>> credentials that I know, without having to deal with manually
>> authenticating?
>>
>> Thanks again.
>>
>> Simon Baynes 
>>
>> On Thursday, March 29, 2012 10:04:12 AM UTC+1, Anash P. Oommen wrote:
>>>
>>> Hi Simon,
>>>
>>> There are couple more pieces to getting OAuth to work on an ASP.NETwebsite.
>>>
>>> 1. There's some initialization code that should go in your Global.asax. 
>>> :  
>>> http://code.google.com/p/google-api-adwords-dotnet/source/browse/trunk/examples/adwords/csharp/oauth/Global.asax.cs
>>>  
>>> 2. There should be some mechanism to trigger the OAuth signup, as shown 
>>> here:
>>>
>>> http://code.google.com/p/google-api-adwords-dotnet/source/browse/trunk/examples/adwords/csharp/oauth/GetAllCampaigns.aspx.cs#58
>>>  
>>>
>>> Hope this helps: Let me know if you have more questions.
>>>
>>> Cheers,
>>> Anash P. Oommen,
>>> AdWords API Advisor.
>>>
>>> On Wednesday, 28 March 2012 20:09:13 UTC+5:30, baynezy wrote:
>>>>
>>>> I am trying (with not much luck) to access the Google AdWords API using 
>>>> the .Net Client 
>>>> Library<http://code.google.com/p/google-api-adwords-dotnet/>to access 
>>>> their 
>>>> SandBox <http://code.google.com/apis/adwords/docs/sandbox.html> API.
>>>>
>>>> Here is my code:-
>>>>
>>>>
>>>>             // create campaign
>>>>             var campaign = new Campaign
>>>>                                {
>>>>                                    name = "Simon's Campaign",
>>>>                                    status = CampaignStatus.ACTIVE,
>>>>                                    servingStatus = 
>>>> ServingStatus.SERVING,
>>>>                                    budget = new Budget
>>>>                                                 {
>>>>                                                     period = 
>>>> BudgetBudgetPeriod.DAILY,
>>>>                                                     amount = new Money
>>>>                                                                  {
>>>>                                                                     
>>>>  microAmount = 100000
>>>>                                                                  },
>>>>                                                     deliveryMethod = 
>>>> BudgetBudgetDeliveryMethod.STANDARD
>>>>                                                 },
>>>>                                    adServingOptimizationStatus = 
>>>> AdServingOptimizationStatus.OPTIMIZE,
>>>>                                    frequencyCap = new FrequencyCap
>>>>                                                       {
>>>>                                                           impressions = 
>>>> 100000,
>>>>                                                           timeUnit = 
>>>> TimeUnit.MINUTE,
>>>>                                                           level = 
>>>> Level.CAMPAIGN
>>>>                                                       }
>>>>                                };
>>>>             var operation = new CampaignOperation {@operator = 
>>>> Operator.ADD, operand = campaign};
>>>>             var operations = new CampaignOperation[1];
>>>>             operations[0] = operation;
>>>>
>>>>
>>>>             // get service
>>>>             var user = new AdWordsUser();
>>>>             var url = Request.Url.GetLeftPart(UriPartial.Path);
>>>>             var config = user.Config as AdWordsAppConfig;
>>>>             user.OAuthProvider = new AdsOAuthNetProvider(
>>>>                     config.OAuthConsumerKey,
>>>>                     config.OAuthConsumerSecret,
>>>>                     AdWordsService.GetOAuthScope(user.Config as 
>>>> AdWordsAppConfig),
>>>>                     url,
>>>>                     Session.SessionID
>>>>                 );
>>>>
>>>>             var service = (CampaignService) 
>>>> user.GetService(AdWordsService.v201109.CampaignService);
>>>>             var page = service.mutate(operations);
>>>>
>>>> When I run this I get an `AdWordsApiException` with an InnerException 
>>>> `AuthenticationError.OAUTH_TOKEN_HEADER_INVALID @ 
>>>>  Service[CampaignService.mutate]`
>>>>
>>>> Now I have the following in my `Web.config`:-
>>>>
>>>>     <!-- Note: For testing purposes, you can use the OAuth consumer 
>>>> key/secret as anonymous/anonymous.-->
>>>>     <add key="AuthorizationMethod" value="OAuth"/>
>>>>     <add key="OAuthConsumerKey" value="anonymous"/>
>>>>     <add key="OAuthConsumerSecret" value="anonymous"/>
>>>>     <!-- Uncomment this key if you want to use v13 sandbox. -->
>>>>     <!-- <add key="LegacyAdWordsApi.Server" value="
>>>> https://sandbox.google.com"/> -->
>>>>     <!-- Uncomment this key if you want to use AdWords API sandbox. -->
>>>>     <add key="AdWordsApi.Server" value="
>>>> https://adwords-sandbox.google.com"/>
>>>>
>>>> As I understand it this is set up correctly, what am I missing?
>>>>
>>>> Any help would be very gratefully received!!!
>>>>
>>>

-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en

Reply via email to