'How do I create a googleads yaml file for python googleads lib?

im trying to use get functions for reports under googleads.

#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

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



Solution 1:[1]

You have to create file 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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 altblog