Exemple #1
0
def main():
    # Authenticate and construct service.
    service, flags = sample_tools.init(
        "",
        "dfareporting",
        "v2.1",
        __doc__,
        __file__,
        parents=[argparser],
        scope=["https://www.googleapis.com/auth/dfareporting", "https://www.googleapis.com/auth/dfatrafficking"],
    )

    profile_id = 1087970

    try:
        # Construct the request.
        request = service.reports().list(profileId=profile_id)

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

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

            if response["items"] and response["nextPageToken"]:
                request = service.reports().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")
def main(report_id, file_id):
  # Authenticate and construct service.
  service, flags = sample_tools.init(
      '', 'dfareporting', 'v2.1', __doc__, __file__, parents=[argparser],
      scope=['https://www.googleapis.com/auth/dfareporting',
             'https://www.googleapis.com/auth/dfatrafficking'])

  report_id = report_id
  file_id = file_id

  report_id_ = int(report_id)
  file_id_ = int(file_id)
  
  print 'Download of file %s started' % (report_id)

  try:
    # Construct the request.
    request = service.files().get_media(reportId=report_id_,fileId=file_id_)
    file_name = str(report_id)+'.csv'
    print 'Execute of file %s started' % (report_id)
    data = request.execute()
    # Execute request and print the file contents
    f = open(file_name, 'w')
    f.write(data)
    f.close()
    print 'Writing of file %s completed' % (report_id)
    #print request.execute()

  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')
Exemple #3
0
def main(argv):
  http, flags = sample_tools.init(
      argv, "mapsengine", "v1", __doc__, __file__, parents=[argparser],
      scope="https://www.googleapis.com/auth/mapsengine")

  if flags.project_id:
    ListTables(http, flags.project_id)
    UploadShapefile(http, flags.project_id, flags.shapefile or "polygons")
  else:
    ListProjects(http)
  return
def main(argv):
    http, flags = sample_tools.init(
        argv,
        "mapsengine",
        "v1",
        __doc__,
        __file__,
        parents=[argparser],
        scope="https://www.googleapis.com/auth/mapsengine",
    )

    if flags.project_id:
        ListTables(http, flags.project_id)
        UploadShapefile(http, flags.project_id, flags.shapefile or "polygons")
    else:
        ListProjects(http)
    return
def main():
    # Authenticate and construct service.
    service, flags = sample_tools.init(
        '', 'dfareporting', 'v2.1', __doc__, __file__, parents=[argparser],
        scope=['https://www.googleapis.com/auth/dfareporting',
             'https://www.googleapis.com/auth/dfatrafficking'])

    with open('IDs.json') as data_file:
        data = json.load(data_file)

    for alldata in data['data']:
        profile_id = data['data'][alldata]['Profile']
        for Reports in data['data'][alldata]['Reports']:
            report_id = data['data'][alldata]['Reports'][Reports]

            try:
                # Construct a get request for the specified report.
                request = service.reports().files().list(profileId=profile_id, reportId=report_id)
                f = open('Reports.txt', 'w')
                while True:
                    # Execute request and print response.
                    response = request.execute()

                    for report_file in response['items']:
                        #f.writelines('Report file with ID %s and file name "%s" has status %s.'
                            #% (report_file['id'], report_file['fileName'],
                                #report_file['status']))
                        f.writelines(report_file['id'])
                        f.writelines('\n')

                    if response['items'] and response['nextPageToken']:
                        request = service.reports().files().list_next(request, response)
                    else:
                        break
                f.close()
            except client.AccessTokenRefreshError:
                print ('The credentials have been revoked or expired, please re-run the '
                    'application to re-authorize')

            f = open('Reports.txt','r')
            file_id = f.readline()
            download(report_id, file_id)
            f.close()