Search code examples
rubygoogle-apigoogle-oauthgoogle-api-clientdouble-click

Cant authenticate to Doubleclick bid manager Api using a service account


i write some code to connect with google api Doubleclick bid manager

I download client_secrets.json at https://console.cloud.google.com/apis/credentials? then run some code like

require 'google/apis/doubleclickbidmanager_v1'
require 'google/api_client/client_secrets'
service = Google::Apis::DoubleclickbidmanagerV1::DoubleClickBidManagerService.new
service.authorization = Google::Auth.get_application_default(['https://www.googleapis.com/auth/doubleclickbidmanager'])
service.download_line_items

it response some errors like:

Sending HTTP post https://www.googleapis.com/doubleclickbidmanager/v1/lineitems/downloadlineitems? 403 #https://www.googleapis.com/doubleclickbidmanager/v1/lineitems/downloadlineitems == 403 (354 bytes) 1091ms> Caught error unauthorizedApiAccess: You are not authorized to use DoubleClick Bid Manager API. Please contact [email protected]. Error - #

Google::Apis::ClientError: unauthorizedApiAccess: You are not authorized to use DoubleClick Bid Manager API. Please contact [email protected]. And when i run api at https://developers.google.com/apis-explorer, it return "You are not authorized to use DoubleClick Bid Manager API. Please contact [email protected]." too Some one know this errors, plz check and help me


Solution

  • When your application requests private data, the request must be authorized by an authenticated user who has access to that data. Every request your application sends to the Google DoubleClick Bid Manager API must include an authorization token. The token also identifies your application to Google.

    This is what the error means by

    "You are not authorized to use DoubleClick Bid Manager API.

    Make sure that you include the following scope when requesting authentication of the user.

    https://www.googleapis.com/auth/doubleclickbidmanager

    More info can be found here and there is documentation here on how to get it working with ruby you will need to alter the example there for your api as this is for calendar.

    Note about service accounts.

    Service accounts must be pre-authorized in order to work. In the case of Google drive you can take the service account email address and share a folder on your google drive with it. Basically you share data with the service account granting it access to the data. Not all google apis support service account authentication. Youtube api, Doubleclick, and blogger I think addsence or adWords as well, are a few that do not support service account authentication as there is no way to share the data with a user without them responding to the share request.