3

I am try to access dbm api , I am authenticating the url using service account please find the sample code below

from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
from httplib2 import Http

scopes =['https://www.googleapis.com/auth/doubleclickbidmanager']


credentials = ServiceAccountCredentials.from_json_keyfile_name(
'path/to/key/.jsonfile', scopes=scopes)

http_auth = credentials.authorize(Http())
body={}

dbm = build('doubleclickbidmanager', 'v1', http=http_auth)
print dbm
request = dbm.lineitems().downloadlineitems(body=body).execute()

print request

If I use oauth mechanism to authenticate the url the code is running properly, since I don't want user interaction, I need server to server mechanism so I used service account

Steps which I tried:

I have created the service account and downloaded the json key file and used in the code but when I try to run my code it throws the following error:

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/doubleclickbidmanager/v1/lineitems/downloadlineitems?alt=json returned "You are not authorized to use DoubleClick Bid Manager API. Please contact dbm-support@google.com.">

Please help , thanks in advance.

Teejay
  • 61
  • 8

2 Answers2

4

As others have said here, you want to log in to the DBM site and add your service account as a user:

Add new user interface

Then, per this documentation, you can set up service account credentials using your client secrets json file. If you want that service account to be able to access reports you've created in DBM under your user account (what you log in with) you need to delegate domain-wide authority:

delegated_credentials = credentials.create_delegated('user@example.org')
http_auth = delegated_credentials.authorize(Http())
dbm = build('doubleclickbidmanager', 'v1', http=http_auth)
queries = dbm.queries().listqueries().execute()['queries']
Nissa
  • 4,589
  • 8
  • 27
  • 37
ahanson
  • 41
  • 3
0

A service account isn't you its a dummy user it has its on Google drive account for example, and by default it doesn't have access to any DoubleClick Bid Manager APIs. Service accounts need to be pre authorized to be able to access private data. So for it to be able to access your double click data you are going to have to grant it access.

Normally with any other API I would say you take the service account email address and add it as a user. I don't have access to double click so I am not even sure if you can add other users manually. They don't have anything in the documentation about service accounts kind of makes me think its not supported. Let us know if you manage to get it to work.

DaImTo
  • 72,534
  • 21
  • 122
  • 346
  • I accept your point " take the service account email address and add it as a user" , can you please tell me the procedure to do this whether i need any admin google account to authorise – Teejay May 03 '16 at 09:20
  • Like I said I don't have a doubleclick bid account so I don't really know you might have to google it. But yes I would assume you would need to be the admin of the doubleclick bid account to add another user if its even possible to add another user to access your account – DaImTo May 03 '16 at 09:39
  • @Teejay I am also experiencing the same problem. Added the service account's email address but my code still throws the same error like yours. – remykarem Oct 27 '16 at 07:05
  • you have give the service account access to the admin directory account like you would any other user. Beyond that sorry I cant help more I don't actually have access to one. – DaImTo Oct 27 '16 at 07:14
  • 1
    Update: I have just added the service account email address as one of the users in DBM itself. The code does not throw any error, but the response I have been getting is an empty body {}. Perhaps you might want to try and get back to us how it goes. – remykarem Oct 27 '16 at 08:34
  • @RaimibinKarim, I am also was able to authorize, just getting an empty body or invalid submitted request error and not being able to get the data! Have you found out? – Gilg Him Jul 29 '19 at 14:06