Adwords OAuth2 using Service Account in C#

1,209 views
Skip to first unread message

Richard

unread,
Apr 3, 2014, 11:13:19 AM4/3/14
to adwor...@googlegroups.com

Hi,
We have an internal c# Adwords application which I trying to upgrade from client login(v201309)  to OAuth2(v201402) 
The application is running by scheduled job to update our Adwords data as well as pulling reports so there is no user interaction involved.
I have followed below example and was able to get as far as initialize the ServiceAccountCredential,  In the example it's using PlusService but I was not able to find any example on  Adwords API with ServiceAccountCredential, 
please advice how to obtain an Access Token from this point. 


            X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable);

            ServiceAccountCredential credential = new ServiceAccountCredential(
              new ServiceAccountCredential.Initializer(SERVICE_ACCOUNT_EMAIL)
              {
                  Scopes = new[] { "https://adwords.google.com/api/adwords/" }
              }.FromCertificate(certificate));

            // Create the service ==> where I am stuck
            //var service = new PlusService(new BaseClientService.Initializer()
            //{
            //    HttpClientInitializer = credential,
            //    ApplicationName = "Plus API Sample",
            //});

            //Activity activity = service.Activities.Get(ACTIVITY_ID).Execute();
            //Console.WriteLine("  Activity: " + activity.Object.Content);
            //Console.WriteLine("  Video: " + activity.Object.Attachments[0].Url);

            //Console.WriteLine("Press any key to continue...");
            //Console.ReadKey();

Josh Radcliff (AdWords API Team)

unread,
Apr 3, 2014, 5:11:54 PM4/3/14
to adwor...@googlegroups.com
Hi,

After the initial OAuth user interaction, you can still perform operations without further user interaction with the Installed Application and Web Application flows as long as you request offline access.  Due to its complexity I recommend considering these other flows before trying to use the service account flow.

Please take a look at the .NET OAuth wiki and post back if you still have trouble with the setup.

Cheers,
Josh, AdWords API Team

Chris Sturgeon

unread,
Jun 1, 2014, 7:00:40 AM6/1/14
to adwor...@googlegroups.com
I am having the same issue. Were you able to figure this out? 



On Thursday, April 3, 2014 11:13:19 AM UTC-4, Richard wrote:

Josh Radcliff (AdWords API Team)

unread,
Jun 2, 2014, 9:40:04 AM6/2/14
to adwor...@googlegroups.com
Hi,

Are you trying to use a Service Account? If so, the .NET library's OAuth2 Guide contains useful information.

If you are using a Service Account, I highly recommend considering the Installed Application or Web Application flow instead. You can achieve very similar results with these flows and they are far easier to set up than the Service Account flow.

Cheers,
Josh, AdWords API Team

Jon Jones

unread,
Aug 22, 2014, 6:20:53 PM8/22/14
to adwor...@googlegroups.com
This is a completely worthless response.
Please show some steps for how to set up a service account.

Josh Radcliff (AdWords API Team)

unread,
Aug 25, 2014, 9:40:37 AM8/25/14
to adwor...@googlegroups.com
Hi,

The documentation in my previous post shows:

b. Step by step instructions on using a service account with the AdWords API: https://developers.google.com/adwords/api/docs/guides/service-accounts

Could you provide more details on what is not clear from those docs, or which step is giving you trouble?

Thanks,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages