googleads / googleads-dfa-reporting-samples

Samples for the DoubleClick for Advertisers Reporting and Trafficking API
Apache License 2.0
106 stars 173 forks source link

campaigns.py #20

Closed rabochoval closed 5 years ago

rabochoval commented 5 years ago

Hi,

I just started with DCM API and need to get list of all campaigns, I also find my profile_id, let say, my profile_id is '8888' Can you please confirm the below code? Because I'm still getting error that the following arguments are required: 8888, is should be int. Am I missing something? It should be straight forward task. Thanks a lot, Lucie


import argparse import sys

import dfareporting_utils from oauth2client import client

profile_id = '8888'

Declare command-line flags.

argparser = argparse.ArgumentParser(add_help=False) argparser.add_argument( profile_id, type=int, help='The ID of the profile to look up advertisers for')

def main(argv):

Retrieve command line arguments.

flags = dfareporting_utils.get_arguments(argv, doc, parents=[argparser])

Authenticate and construct service.

service = dfareporting_utils.setup(flags)

profile_id = flags.profile_id

try:

Construct the request.

request = service.advertisers().list(profileId=profile_id)

while True:
  # Execute request and print response.
  response = request.execute()

  for advertiser in response['advertisers']:
    print ('Found advertiser with ID %s and name "%s".'
           % (advertiser['id'], advertiser['name']))

  if response['advertisers'] and response['nextPageToken']:
    request = service.advertisers().list_next(request, response)
  else:
    break

except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')

if name == 'main': main(sys.argv)


jimper commented 5 years ago

Hi there,

The Python samples are designed to read necessary values from the command line, there's no need to hardcode anything. Ex:

$ python get_campaigns.py 8888

Regards, - Jonathon Imperiosi, DCM API Team

rabochoval commented 5 years ago

Hi there,

thanks a lot, it works perfect. but still if I want to hardcode, any link with example?

jimper commented 5 years ago

I don't have anything to link to, but at a high level you'd probably want to:

  1. Remove the calls to argparser.add_argument().
  2. Update any assignments that are using values from the flags object to instead use hardcoded values. Ex:
profile_id = flags.profile_id

becomes

profile_id = 8888

Regards, - Jonathon Imperiosi, DCM API Team

rabochoval commented 5 years ago

Thanks a lot, it is working now.