Search code examples
c#winformsgoogle-api-dotnet-clientdouble-click-advertising

Call a DoubleClick Bid Manager API


I am writing my first Google APIs Winforms application and I'm unable to figure out how to make an API call.

The example in this google "get started" documentation is not helping a lot.

I have a Client ID and secret and have authorized my app using these.

ClientSecrets cs = new ClientSecrets { ClientId = "<...>.apps.googleusercontent.com", ClientSecret = "<...>" };

var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(cs, new[] { @"https://www.googleapis.com/auth/doubleclickbidmanager" }, "user", 
            System.Threading.CancellationToken.None, new Google.Apis.Util.Store.FileDataStore(@"C:\temp", true));

I now want to call this API and see its results.

Can someone give me pointers on how do I go about it?


Solution

  • Install the nugget package Install-Package Google.Apis.Doubleclickbidmanager.v1

    The following code should work for Oauth2

    string clientId = "ddd";
    string clientSecret = "ddd";
    
    var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
                                                                                        , scopes
                                                                                        , "test"
                                                                                        , CancellationToken.None
                                                                                        , new FileDataStore(".",true)).Result;
    
       var service = new DoubleClickBidManagerService(new BaseClientService.Initializer()
           {
           HttpClientInitializer = credential,
           ApplicationName = "xyz",    
           });
    

    All your calls should go though the service

    service.Lineitems.Downloadlineitems(body).Execute();