0

I am having trouble authenticating myself using the DoubleClick Bid Manager API I have set up a service account as per Google's instructions and am using the Google APIs PHP client library. Following the documentation, my code looks like this:

require_once 'Google/autoload.php';

$client_email = 'myemail.com';

$private_key = file_get_contents('myfilename.p12');

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

$credentials = new Google_Auth_AssertionCredentials(
    $client_email,
    $scopes,
    $private_key,
);




$client = new Google_Client();

$client->setAssertionCredentials($credentials);

if ($client->getAuth()->isAccessTokenExpired()) {
    $client->getAuth()->refreshTokenWithAssertion();
}

$service =  new Google_Service_DoubleClickBidManager($client);
$response = $service->queries->listqueries();

The last line provokes an error:

Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/doubleclickbidmanager/v1/queries: (403) You are not authorized to use DoubleClick Bid Manager API. Please contact bidmanager-support@google.com.'

I have emailed them but I'm not sure if there is any one there providing support for technical questions. I've reread the documentation, I can't see where I am going wrong. If anyone has been through this before or has any pointers, they will be much appreciated!!!

Many thanks

PS I set up my API access earlier this week. Again, I followed the instructions in the documentation and received the last confirmation email from Google regarding setup, so everything should be good to go in that respect as well

  • Either its your private credentials thats incorrect, else, your account is not allowed to do that query. Its probably nothing wrong with the code. – Kishor May 21 '15 at 09:58

2 Answers2

1

The DoubleClick Bid Manager does not support Service Accounts. They use the user's permissions in DBM to define the permissions for the API requests, so a user based authentication is required.

pxlator
  • 13
  • 5
1

You probably need to add the user email of the service account to DV 360 with read/write role.

This is how I did it using google api client library for ruby:

1- First create a GOOGLE_APPLICATION_CREDENTIALS environment variable:

$ export GOOGLE_APPLICATION_CREDENTIALS='[Path to your client_secrets.json]

2- instatiate a service variable to connect to the api and assign the authorization to it:

scopes = 'https://www.googleapis.com/auth/doubleclickbidmanager'
authorization = Google::Auth.get_application_default(scopes)
service = Google::Apis::DoubleclickbidmanagerV1::DoubleClickBidManagerService.new
service.authorization = authorization
service.authorization.fetch_access_token!

# This line would return results from the api
service.download_line_items

Notice that the email account in the .json secrets file must be added as a user with read/write role on DV360

Gilg Him
  • 842
  • 10
  • 19