Google Ads API Update - v10, ERROR: "unexpected input DURING"
Google Ads API Update - v10, ERROR: "unexpected input DURING"
Google 广告 API 最近停止了一个旧版本 - https://ads-developers.googleblog.com/2021/04/upgrade-to-google-ads-api-from-adwords.html.
话虽这么说,我正在尝试将我的查询调整为新的 api 标准,但出现了最奇怪的错误 "unexpected input DURING"
-- 下面有更多详细信息。根据此文档,这似乎是正确的:https://developers.google.com/google-ads/api/docs/samples/get-hotel-ads-performance
请注意上面文档中 SQL 查询示例中使用的“DURING”。
下面是我的错误信息,下面是脚本:
错误:
SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428
Request made: ClientCustomerId:, Host: googleads.googleapis.com, Method: /google.ads.googleads.v8.services.GoogleAdsService/SearchStream, RequestId:, IsFault: True, FaultMessage:
Error in query: unexpected input DURING.
脚本:
import sys, json, io, gzip, sys, os
from googleads import adwords
import pandas as pd
import numpy as np
def google_ads_extract(client,customer_id, s3_path,fields,report_type,statuses,date_range, download_version, job_name):
ga_service = client.get_service("GoogleAdsService")
search_request=client.get_type("SearchGoogleAdsStreamRequest")
search_request.customer_id = customer_id
query = f"SELECT {', '.join(str(x) for x in fields)} FROM {str(report_type[0])} WHERE Status IN {*statuses,} DURING {date_range}"
# query = "SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428"
print(query)
search_request.query = query
stream = ga_service.search_stream(search_request)
for batch in stream:
for row in batch.results:
print(row)
return 1
至select您将使用的时间范围
segments.date BETWEEN '2019-01-01' AND '2019-01-31'
但是因为你有 UTC,所以你可以尝试,但由于我目前无法测试它,你最好 运行 像 abouve
这样的日期
SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion
FROM CRITERIA_PERFORMANCE_REPORT
WHERE Status IN ('ENABLED', 'PAUSED')
AND segments.date BETWEEN TIMESTAMP_SECONDS(20220427) AND TIMESTAMP_SECONDS(20220428)
Google 广告 API 最近停止了一个旧版本 - https://ads-developers.googleblog.com/2021/04/upgrade-to-google-ads-api-from-adwords.html.
话虽这么说,我正在尝试将我的查询调整为新的 api 标准,但出现了最奇怪的错误 "unexpected input DURING"
-- 下面有更多详细信息。根据此文档,这似乎是正确的:https://developers.google.com/google-ads/api/docs/samples/get-hotel-ads-performance
请注意上面文档中 SQL 查询示例中使用的“DURING”。
下面是我的错误信息,下面是脚本:
错误:
SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428
Request made: ClientCustomerId:, Host: googleads.googleapis.com, Method: /google.ads.googleads.v8.services.GoogleAdsService/SearchStream, RequestId:, IsFault: True, FaultMessage:
Error in query: unexpected input DURING.
脚本:
import sys, json, io, gzip, sys, os
from googleads import adwords
import pandas as pd
import numpy as np
def google_ads_extract(client,customer_id, s3_path,fields,report_type,statuses,date_range, download_version, job_name):
ga_service = client.get_service("GoogleAdsService")
search_request=client.get_type("SearchGoogleAdsStreamRequest")
search_request.customer_id = customer_id
query = f"SELECT {', '.join(str(x) for x in fields)} FROM {str(report_type[0])} WHERE Status IN {*statuses,} DURING {date_range}"
# query = "SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428"
print(query)
search_request.query = query
stream = ga_service.search_stream(search_request)
for batch in stream:
for row in batch.results:
print(row)
return 1
至select您将使用的时间范围
segments.date BETWEEN '2019-01-01' AND '2019-01-31'
但是因为你有 UTC,所以你可以尝试,但由于我目前无法测试它,你最好 运行 像 abouve
这样的日期SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion
FROM CRITERIA_PERFORMANCE_REPORT
WHERE Status IN ('ENABLED', 'PAUSED')
AND segments.date BETWEEN TIMESTAMP_SECONDS(20220427) AND TIMESTAMP_SECONDS(20220428)