Yuma 4×4

Media and Communications

Making Requests to Google Ad Manager API with .NET

Making Requests to Google Ad Manager API with .NET

SPEAKER 1: This video will
show you how to make a simple request to the Ad Manager API
using Google’s .NET client library. This video assumes you already
set up a service account on your Ad Manager network,
and that you have a basic familiarity with
C# and .NET Core. Even though this video
will be using .NET Core, it should be noted that you can
use this client library with the .NET framework as well. Navigate your browser to
the googleads-dotnet-lib repository. Under source Ad Manager you will
find a file named app.config. The .NET client library expects
to find this configuration file in your project directory. Click the Raw button in
GitHub and save this file as a template. For now we’ll put it
in the home directory. Be sure that the file has the
correct extension, .config. Next, open a terminal to
set up a .NET project. Start by making a
project directory and moving the
app.config file there, and then move into
that directory. Let’s create a new console
app with the .NET new console command. Then let’s add the
Ad Manager package. For historical reasons,
it’s called google.dfp. Now open your
development environment. I’m using Visual Studio
Code and Open Source IDE. Then open your project directory
and select the app.config file for editing. First enter an application name. This string will be sent to
Google with every request, and should identify
your application. It’s important that
your application name be unique and
descriptive, since it can help Google
identify requests coming from your application. This can make it easier
for us to provide you with support later on. Next, you need to enter
your network code. And finally, you must add
your authentication method. In this example, let’s uncomment
the service account section and then enter the path
to the JSON key file you downloaded in
the OAuth video. Be sure to save your changes
to this configuration file. Next, open the program.cs
file to start writing C# code. First, add a using
statement for the version independent resources at
google.api.ads.admanager.lib. Then, add a using statement for
the latest version of the API. Then, in the main method, create
an Ad Manager user instance like so. Next, create a using
block to encapsulate the code that will need to
access an Ad Manager service. In this case, we’re using
the network service. Then, create a network instance
by calling get current network on the network service. It’s important to point out that
this method is what’s actually making a request to
the Ad Manager API, and it returns an object
representing the API response. All that’s left to do now is
to print out some information from the response. Let’s show the network
code and the display name for the current network. Save this C# file and open a
terminal to run this example. As you can see,
it has printed out the data it retrieved from
the Ad Manager network. And that’s it. You are now up and running
with the Ad Manager API using Google’s .NET client library.

Leave comment

Your email address will not be published. Required fields are marked with *.