首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Python中将Google Ads报告导出为csv?(获取AuthenticationError和HTTP错误400)

问如何在Python中将Google Ads报告导出为csv?(获取AuthenticationError和HTTP错误400)
EN

Stack Overflow用户
提问于 2018-12-21 18:59:03
回答 1查看 1.8K关注 0票数 2

连接到ads api,使用凭据配置yaml并测试google的python示例代码,但收到上述错误。如何始终将简单的关键字性能报告导出到csv?

使用Jupyter在Python 3.6上测试和运行代码。我在这里使用了代码:https://github.com/googleads/googleads-python-lib/tree/master/examples/adwords/v201809/reporting

代码语言:javascript
复制
#!/usr/bin/env python
#
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This example downloads a criteria performance report with AWQL.

To get report fields, run get_report_fields.py.

The LoadFromStorage method is pulling credentials and properties from a
"googleads.yaml" file. By default, it looks for this file in your home
directory. For more information, see the "Caching authentication information"
section of our README.

"""

import sys
from googleads import adwords


def main(client):
  # Initialize appropriate service.
  report_downloader = client.GetReportDownloader(version='v201809')

  # Create report query.
  report_query = (adwords.ReportQueryBuilder()
                  .Select('CampaignId', 'AdGroupId', 'Id', 'Criteria',
                          'CriteriaType', 'FinalUrls', 'Impressions', 'Clicks',
                          'Cost')
                  .From('CRITERIA_PERFORMANCE_REPORT')
                  .Where('Status').In('ENABLED', 'PAUSED')
                  .During('LAST_7_DAYS')
                  .Build())

  # You can provide a file object to write the output to. For this
  # demonstration we use sys.stdout to write the report to the screen.
  report_downloader.DownloadReportWithAwql(
      report_query, 'CSV', sys.stdout, skip_report_header=False,
      skip_column_header=False, skip_report_summary=False,
      include_zero_impressions=True)


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()

  main(adwords_client)

或者使用了以下命令,但得到了相同的错误:

代码语言:javascript
复制
# Using Pandas

from googleads import adwords
import pandas as pd
import numpy as np
import io

# Define output as a string
output = io.StringIO()

# Initialize appropriate service.
adwords_client = adwords.AdWordsClient.LoadFromStorage()

report_downloader = adwords_client.GetReportDownloader(version='v201809')

# Create report query.
report_query = ('''
select Date, HourOfDay, Clicks
from ACCOUNT_PERFORMANCE_REPORT
during LAST_7_DAYS''')

# Write query result to output file
report_downloader.DownloadReportWithAwql(
    report_query, 
    'CSV',
    output,
    client_customer_id='xxx-xxx-xxxx', # denotes which adw account to pull from
    skip_report_header=True, 
    skip_column_header=False,
    skip_report_summary=True, 
    include_zero_impressions=False)


output.seek(0)

df = pd.read_csv(output)

df.head()

期望某种类型的输出与指定的google广告报告。

EN

回答 1

Stack Overflow用户

发布于 2018-12-21 22:58:32

client_customer_id='xxx-xxx-xxxx'正在查看主帐户,而不是客户端帐户,并进行了更新,现在可以正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53883610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档