Yuma 4×4

Media and Communications

Making Requests to Ad Manager API with Python

Making Requests to Ad Manager API with Python

video will show you how to make a simple request
to the Ad Manager API using Google’s Python Client Library. This video assumes you’ve
already set up a service account on your
Ad Manager network and that you have a basic
familiarity with Python and the command line. Navigate your browser to
the Google Ads Python lib. There, you will find a
file named googleads.yaml. The Python Client
Library expects to find this configuration
file in your home directory. Click the raw button in GitHub
and save this file to your home directory as a template. If you’re on a Windows
machine, this will be c:/users/ your username. Also, be sure that the file has
the correct extension, .yaml. Next, open the yaml
file and a text editor and find the Ad Manager section. Here, you’ll need to
enter an application name. This is a string
that 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
a request coming from your application. This can make it easier
for us to provide you with support later on. You’ll also need to
enter your network code. And finally, the
path to the key file you downloaded in Oath video. Be sure to save your changes
to this configuration file. We’re almost ready to
start writing Python code. To set up your
environment, you can use the virtual end
of command and then activate it by running
the activate script within the bin directory of
the newly created folder. On Windows, this
will be a batch file. Then install the Google Ads
Python library with PIP. This may take a few
minutes to install all of the dependencies. Now, open a new .py
file and a text editor. First, import the
ad_manager module from the googleads module. Then use the Ad Manager
client’s LoadFromStorage method to create a client instance. This will load your credentials
from the service account file. In this example, we’re going
to use the network service. To do this, use the
GetService method on the ad_manager_client
instance you just created. You can specify the version
number here if you’d like, or you can leave it
off and the library will use the newest API
version that your client library supports. Now, you’re ready to make a
request to the Ad Manager API. This can be done
simply by calling the method we want on the
service instance we’ve created. In this example, we’ll get
the current Ad Manager network that our integration can access. It’s important to point out that
this method is what’s actually making a request to
the Ad Manager API and it returns a Python
dictionary representing the API response object. All that’s left to do now is
to print out some information from the response. Let’s show the
networks displayName and the networkCode. Now, we can save
and run the script. 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 Python
Client Library.

Leave comment

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