#!/usr/bin/env python
# coding: utf-8
# In[33]:
#!/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 as a string 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.
"""
from googleads import adwords
import io
import pandas as pd
adwords_client = adwords.AdWordsClient.LoadFromStorage()
# Initialize appropriate service.
report_downloader = adwords_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())
output = io.StringIO()
report_downloader.DownloadReportWithAwql(
report_query, 'CSV', output, skip_report_header=True,
skip_column_header=False, skip_report_summary=True,
include_zero_impressions=True)
output.seek(0)
df = pd.read_csv(output)
print(df.head())
# In[44]:
df.to_csv("/Users/ezerivarola/Desktop/Google_ADS_API/report1.csv",index=False)
# In[ ]:
并且我正在尝试使用crontab通过以下命令进行调度:
* * * * * /usr/local/bin/python3 /Users/ezerivarola/Desktop/Google_ADS_API/Report1_DF.py
但是,虽然我没有收到任何错误,并且在查看邮件时我看到它正在运行,但是脚本的csv文件并未生成。
有人有什么错的想法吗?
我有在anaconda中执行过的python脚本,并以.py#!/ usr / bin / env python#的形式下载到本地工作区中#编码:utf-8#在[33]:#!/ usr / bin / env python ##版权所有2016 Google Inc.全部...
您需要在开始时更改5 *以匹配您希望它运行的时间段,