Setting values on Wrapper Types
Many of the fields on the objects in the Google Ads API are a
Wrapper Type, which includes
types such as StringValue
and Int64Value
. In the Python client library there
are two ways to set the values for Wrapper types.
Set the
value
field directly (recommended)All protobuf objects retrieved from the client already have Wrapper Types as values for the appropriate fields and you can set their values by reassigning their
value
field. For example, thename
field on a Campaign object is aStringValue
:from google.ads.google_ads import client campaign = client.get_type('Campaign') campaign.name.value = 'campaign name'
Initialize a Wrapper Type and copy it onto the object
Using the same example above, here is how you can copy an existing Wrapper Type onto a protobuf object:
from google.ads.google_ads import client string_value = client.get_type('StringValue') campaign = client.get_type('Campaign') string_value.value = 'campaign name' campaign.name.CopyFrom(string_value)
As you can see setting the value
field on Wrapper Types is more concise and
required less code. It is therefore the recommended way to update Wrapper Types
in the Python client library.