GoogleBidManager在保存的查询上运行查询

2024-10-02 10:28:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个python函数,它将在googlecloud函数上运行,以便从DBM(googlebidmanager/DisplayVideo 360)提取数据。你知道吗

我最初使用的是createquery函数,它允许我创建查询并在请求中发送它。但是,由于API在某些维度和度量组合方面的限制,我想将其切换为开始使用runquery。你知道吗

我已经在DBM上创建了一个查询,我想让cloud函数在每次需要时都运行它,我将使用listreportsAPI获取最新的报告。你知道吗

我的主要问题是,当我尝试使用runquery(queryId=651937704)函数时,总是会出现以下错误:

textPayload: "Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 383, in run_background_function
    _function_handler.invoke_user_function(event_object)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 217, in invoke_user_function
    return call_user_function(request_or_event)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 214, in call_user_function
    event_context.Context(**request_or_event.context))
  File "/user_code/main.py", line 127, in create_google_bidmanager_report
    bidmanager_report(doubleclick_bid_manager, day_start, day_end)
  File "/user_code/main.py", line 26, in bidmanager_report
    response = doubleclick_bid_manager.queries().runquery(body=data, queryId=651937704).execute()
  File "/env/local/lib/python3.7/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/env/local/lib/python3.7/site-packages/googleapiclient/http.py", line 856, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 503 when requesting https://www.googleapis.com/doubleclickbidmanager/v1/query/651937704? returned "Woops. We are currently having some issues.">"

下面是我正在使用的python代码:

from google.cloud import datastore
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient import discovery
from httplib2 import Http
from datetime import datetime

datastore_client = datastore.Client()


def create_credentials():
    scopes = ['https://www.googleapis.com/auth/doubleclickbidmanager']

    credentials = ServiceAccountCredentials.from_json_keyfile_name('JSON_KEY_FILE.json', scopes=scopes)

    http_auth = credentials.authorize(Http())

    doubleclick_bid_manager = discovery.build('doubleclickbidmanager', 'v1', http=http_auth)

    return doubleclick_bid_manager


def bidmanager_report(doubleclick_bid_manager, day_start, day_end):
    data = {
        "dataRange": "PREVIOUS_DAY"
    }
    response = doubleclick_bid_manager.queries().runquery(queryId=651937704, body=data).execute()


def create_google_bidmanager_report(data, context):
    doubleclick_bid_manager = create_credentials()

    today = datetime.now()
    day_start = datetime(year=today.year, month=today.month, day=today.day, hour=0, minute=0, second=0)
    day_end = datetime(year=today.year, month=today.month, day=today.day, hour=23, minute=59, second=59)

    bidmanager_report(doubleclick_bid_manager, day_start, day_end)

错误发生在此行: response = doubleclick_bid_manager.queries().runquery(queryId=651937704, body=data).execute()

错误日志中如上所示的错误是: Woops. We are currently having some issues.

是否有其他方法来运行已保存的查询,或者我是否应该返回以创建查询?你知道吗


Tags: infrompyreporttodaygooglelinemanager

热门问题