简体   繁体   English

如何为 python googleads lib 创建 googleads yaml 文件?

[英]How do I create a googleads yaml file for python googleads lib?

im trying to use get functions for reports under googleads.我试图在 googleads 下使用 get 函数进行报告。

#My code #我的代码

from googleads import adwords
from googleads import errors
import time
import datetime
import os
import sys

if __name__ == '__main__':

  ## initialize google adwords client object
  adwords_client = adwords.AdWordsClient.LoadFromStorage("googleAds.yaml")

  ## set your customer-ID
  adwords_client.SetClientCustomerId('389204095687-xx.apps.googleusercontent.com')

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

  ## get CLICK_PERFORMANCE report for yesterday as an example
  report_date = datetime.datetime.now()-datetime.timedelta(days=1)
  report_date_string = report_date.strftime("%Y%m%d")

  ## build the report query
  report_query = (adwords.ReportQueryBuilder()
      .Select('campaign.id','ad_group.id', 'metrics.impressions', 'metrics.clicks')
      .From('ad_group')
      .During(start_date=report_date_string,end_date=report_date_string)
      .Build())

  ## download the report as CSV into string
  csv_report = report_downloader.DownloadReportWithAwql(
      report_query, 'CSV', skip_report_header=True,
      skip_column_header=True, skip_report_summary=True,
      include_zero_impressions=False)
  

But i receive the below traceback error-但我收到以下回溯错误-

   with open(path, 'rb') as handle:

FileNotFoundError: [Errno 2] No such file or directory: 'googleAds.yaml'


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "<ipython-input-5-d90ad0259074>", line 16, in <module>
    adwords_client = adwords.AdWordsClient.LoadFromStorage("googleAds.yaml")

  File "C:\Users\jj\AppData\Local\Continuum\anaconda3\lib\site-packages\googleads\adwords.py", line 193, in LoadFromStorage
    cls._OPTIONAL_INIT_VALUES))

  File "C:\Users\jj\AppData\Local\Continuum\anaconda3\lib\site-packages\googleads\common.py", line 247, in LoadFromStorage
    'Given yaml file, %s, could not be opened.' % path)

GoogleAdsValueError: Given yaml file, googleAds.yaml, could not be opened.

I reviewed the documentation for Oath: https://github.com/googleads/googleads-python-lib/wiki/API-access-using-own-credentials-(installed-application-flow)#step-2---setting-up-the-client-library我查看了 Oath 的文档: https://github.com/googleads/googleads-python-lib/wiki/API-access-using-own-credentials-(installed-application-flow)#step-2---setting -up-the-client-library

but I already have all the credentials, i just dont know how to create the yml file and save it where python can detect it但我已经拥有所有凭据,我只是不知道如何创建 yml 文件并将其保存在 python 可以检测到的位置

You have to create file googleAds.yaml.您必须创建文件 googleAds.yaml。 It has format like:它的格式如下:

use_proto_plus: True
developer_token: 1231jjhkj1jk12312bh51w
client_id: 156688168548-qeqwe32423423431561f65sf4sd56f44.apps.googleusercontent.com
client_secret: FSSFSD-QDGETERTEGSDG_D4ERG43LKMSDF8
refresh_token: 1//KMDFGDF0DFGDFLKMLKDMK-LDGDFGDFLMLK3245KL23LMLSKDMFLSKDMLK342LKMKLMLFKSFLKSMLKM34LKM;SSn-ST-ZQ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM