exchange Client migration setup problem/questions with python googleapiclient discovery

23 views
Skip to first unread message

Chunyee Leung

unread,
May 20, 2021, 2:41:18 PM5/20/21
to Authorized Buyers API Forum
Hi,

We are migrating from ad exchange buyer API (v1.3) to realtimebidding API before the July deadline. I have a number of code questions. 

Setup client service

Using googleapiclient discovery. the parameters were changed from 

self.client = build('adexchangebuyer', 'v1.3', http=http)
to
self.client = build('realtimebidding',  'v1.0' , http=http)

1. what service name and version value should I assign or pass into? Is the googleapiclient version I am using suffice to perform the migration?

Instead right now  I am getting the following error 
    ('/opt/optms/env/lib/python2.7/site-packages/googleapiclient/discovery.py',

                                   303,

                                   'build',

                                   'raise UnknownApiNameOrVersion("name: %s  version: %s" % (serviceName, version))')],

                        'type': "<class 'googleapiclient.errors.UnknownApiNameOrVersion'>",

                        'value': 'name: realtimebidding  version: v1.0'},

          'message': None},

Our code are still using python 2.7 and not able to upgrade to python. 3.x for our various reasons. Next we are going with  google-api-python-client==1.12.8. from google-api-python-client==1.6.5.    but not going  up to 2.x


Next On credentials and scope

 From using the following values

"SCOPE": "https://www.googleapis.com/auth/adexchange.buyer",
"VERSION": "v1.3",

"ACCOUNT_ID": ?????????,

"SERVICE_ACCOUNT_EMAIL": "?????@developer.gserviceaccount.com",
"KEY_FILE": "?????????.p12",

Changing to or staying with. 

different Scope  but same key file, same  email and account_id

"SERVICE_ACCOUNT_EMAIL": "?????@developer.gserviceaccount.com",
"KEY_FILE": "?????????.p12",
"SCOPE": "https://www.googleapis.com/auth/realtime-bidding",


2. Is the Scope value correct? do I need to set http?

3. Do I need to acquire a different key and/or key file type when performing our migration or can we stay with what we are using?

The  exact initialization code as follows

http = httplib2.Http()
credentials = ServiceAccountCredentials.from_p12_keyfile(
SERVICE_ACCOUNT_EMAIL,
os.path.dirname(os.path.realpath(__file__)) + "/" + "KEY_FILE",
scopes=SCOPE
)
http = credentials.authorize(http)
self.client = build('realtimebidding', version=VERSION, http=http)

Any other info and hints to get pass this API exception trying to connect and make the API request will be great (our task is submitting Creatives supported now in the real time bidding API from the current adexchangebuyer creative API)

Thanks very much


Chunyee Leung

Inmar Intelligence





Mark Saniscalchi

unread,
May 20, 2021, 4:01:45 PM5/20/21
to Authorized Buyers API Forum
Hello Chunyee,

Our Getting Started Guide goes over this a bit, and our Python samples step through the process of setting up a client–the first_api_request.py sample is self-contained and should show everything involved in configuring a client and making an API call. Of course, one problem you alluded to is the earlier version of the client library, but I expect that would work because the Python library generates a client dynamically from the retrieved discovery document. It just might have some incompatibilities with the latest samples.

I'll answer your questions in order:
  1. The name you should be specifying is "realtimebidding", and the version specified should be "v1".
  2. The scope looks correct.
  3. It looks like you're using the Service Account flow (which we recommend), so you would not need to use a different one to access the Real-time Bidding API. However, you would need to update the API scope–you could hypothetically specify both the Ad Exchange Buyer and Real-time Bidding API scopes if you need to access both during the transition.
Based on the error message provided, it looks like the cause is that you specified "v1.0 " rather than just "v1". I suspect if you made that change, you would be able to create the client.

Regards,
Mark
Reply all
Reply to author
Forward
0 new messages