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 advertiser_id = flags.advertiser_id try: # Construct a landing page object. landing_page = { 'name': 'Test Landing Page #%s' % uuid.uuid4(), 'advertiserId': advertiser_id, 'archived': 'false', 'url': 'https://www.google.com' } request = service.advertiserLandingPages().insert(profileId=profile_id, body=landing_page) # Execute request and print response. response = request.execute() print('Created advertiser landing page with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 advertiser_group_id = flags.advertiser_group_id advertiser_id = flags.advertiser_id try: # Construct the request. advertiser = { 'advertiserGroupId': advertiser_group_id } request = service.advertisers().patch( profileId=profile_id, id=advertiser_id, body=advertiser) # Execute request and print response. response = request.execute() print ('Assigned advertiser with ID %s to advertiser group with ID %s.' % (response['id'], response['advertiserGroupId'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 advertiser_id = flags.advertiser_id try: # Construct and save campaign. campaign = { 'name': 'Test Campaign', 'advertiserId': advertiser_id, 'archived': 'false', 'startDate': '2015-01-01', 'endDate': '2020-01-01' } request = service.campaigns().insert( profileId=profile_id, defaultLandingPageName='Test Landing Page', defaultLandingPageUrl='http://www.google.com', body=campaign) # Execute request and print response. response = request.execute() print ('Created campaign with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 advertiser_id = flags.advertiser_id image_url = flags.image_url size_id = flags.size_id try: # Construct the basic creative structure. creative = { 'advertiserId': advertiser_id, 'name': 'Test redirect creative', 'redirect_url': image_url, 'size': {'id': size_id}, 'type': 'REDIRECT' } request = service.creatives().insert(profileId=profile_id, body=creative) # Execute request and print response. response = request.execute() print ('Created redirect creative with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 a get request for the specified profile. request = service.files().list(profileId=profile_id) while True: # Execute request and print response. response = request.execute() for report_file in response['items']: print( 'File with ID %s and file name "%s" has status "%s" with date range "%s".' % (report_file['id'], report_file['fileName'], report_file['status'], report_file['dateRange'])) if response['items'] and response['nextPageToken']: request = service.files().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(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 activity_id = flags.activity_id try: # Construct the request. request = service.floodlightActivities().generatetag( profileId=profile_id, floodlightActivityId=activity_id) # Execute request and print response. response = request.execute() if 'globalSiteTagGlobalSnippet' in response: # Print both global snippet and event snippet. print('Global site tag global snippet:\n\n%s' % response['globalSiteTagGlobalSnippet']) print('\n\nGlobal site tag event snippet:\n\n%s' % response['floodlightActivityTag']) else: # Print the Floodlight activity tag. print('Floodlight activity tag:\n\n%s' % response['floodlightActivityTag']) except client.AccessTokenRefreshError: print('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 advertiser_id = flags.advertiser_id try: # Construct the basic creative structure. creative = { 'advertiserId': advertiser_id, 'name': 'Test tracking creative', 'type': 'TRACKING_TEXT' } request = service.creatives().insert(profileId=profile_id, body=creative) # Execute request and print response. response = request.execute() print('Created tracking creative with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 campaign_id = flags.campaign_id creative_id = flags.creative_id try: # Construct the request. association = {'creativeId': creative_id} request = service.campaignCreativeAssociations().insert( profileId=profile_id, campaignId=campaign_id, body=association) # Execute request and print response. response = request.execute() print('Creative with ID %s is now associated with campaign %s.' % (response['creativeId'], campaign_id)) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 field_id = flags.field_id try: # Construct the request. request = service.creativeFieldValues().list( profileId=profile_id, creativeFieldId=field_id) while True: # Execute request and print response. response = request.execute() for value in response['creativeFieldValues']: print ('Found creative field value with ID %s and value "%s".' % (value['id'], value['value'])) if response['creativeFieldValues'] and response['nextPageToken']: request = service.creativeFieldValues().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(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 ad_id = flags.ad_id try: # Retrieve the ad. ad = service.ads().get(profileId=profile_id, id=ad_id).execute() # Retrieve a single targetable remarketing list for the ad. lists = service.targetableRemarketingLists().list( profileId=profile_id, advertiserId=ad['advertiserId'], maxResults=1).execute() if lists['targetableRemarketingLists']: list = lists['targetableRemarketingLists'][0] # Update the ad with a list targeting expression ad['remarketing_list_expression'] = { 'expression': list['id'] } response = service.ads().update(profileId=profile_id, body=ad).execute() print ('Ad %s updated to use remarketing list expression: "%s".' % (response['id'], response['remarketing_list_expression']['expression'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 campaign_id = flags.campaign_id try: # Construct and save event tag. event_tag = { 'campaignId': campaign_id, 'name': 'Test Campaign Event Tag', 'status': 'ENABLED', 'type': 'CLICK_THROUGH_EVENT_TAG', 'url': 'https://www.google.com' } request = service.eventTags().insert(profileId=profile_id, body=event_tag) # Execute request and print response. response = request.execute() print('Created campaign event tag with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 floodlight_config_id = flags.floodlight_config_id try: # Construct and save floodlight activity group. activity_group = { 'name': 'Test Floodlight Activity Group', 'floodlightConfigurationId': floodlight_config_id, 'type': 'COUNTER' } request = service.floodlightActivityGroups().insert( profileId=profile_id, body=activity_group) # Execute request and print response. response = request.execute() print('Created floodlight activity group with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 advertiser_id = flags.advertiser_id try: # Construct the request. request = service.changeLogs().list( profileId=profile_id, objectIds=[advertiser_id], objectType='OBJECT_ADVERTISER') while True: # Execute request and print response. response = request.execute() for change_log in response['changeLogs']: print( '%s: Field "%s" from "%s" to "%s".' % (change_log['action'], change_log['fieldName'], change_log['oldValue'], change_log['newValue'])) if response['changeLogs'] and response['nextPageToken']: request = service.changeLogs().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(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 campaign_id = flags.campaign_id placement_id = flags.placement_id try: # Construct the request. request = service.placements().generatetags( profileId=profile_id, campaignId=campaign_id, placementIds=[placement_id]) # Execute request and print response. response = request.execute() for placement_tag in response['placementTags']: print_placement_tag(placement_tag) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 report_id = flags.report_id try: # 1. Find a file to download. report_file = find_file(service, profile_id, report_id) if report_file: # 2. (optional) Generate browser URL. generate_browser_url(service, report_id, report_file['id']) # 3. Directly download the file. direct_download_file(service, report_id, report_file['id']) else: print 'No file found for profile ID %d and report ID %d.' % (profile_id, report_id) except client.AccessTokenRefreshError: print('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 account_id = flags.account_id parent_role_id = flags.parent_role_id try: # Construct the basic user role structure. user_role = { 'name': 'Test User Role', 'accountId': account_id, 'parentUserRoleId': parent_role_id } request = service.userRoles().insert(profileId=profile_id, body=user_role) # Execute request and print response. response = request.execute() print ('Created user role with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 report_id = flags.report_id try: # Create a report resource with the fields to patch report = { 'criteria': { 'dateRange': {'relativeDateRange': 'YESTERDAY'} } } # Construct the request. request = service.reports().patch( profileId=profile_id, reportId=report_id, body=report) # Execute request and print response. result = request.execute() print ('Successfully patched %s report with ID %s.' % (result['type'], result['id'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 height = flags.height width = flags.width try: # Construct the request. request = service.sizes().list( profileId=profile_id, height=height, width=width) # Execute request and print response. result = request.execute() for size in result['sizes']: print 'Found size with ID %s.' % (size['id']) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 and save content category. content_category = {'name': 'Test Category'} request = service.contentCategories().insert(profileId=profile_id, body=content_category) # Execute request and print response. response = request.execute() print('Created content category with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 activity_group_id = flags.activity_group_id try: # Construct and save spotlight activity. floodlight_activity = { "countingMethod": "STANDARD_COUNTING", "expectedUrl": "http://www.google.com", "floodlightActivityGroupId": activity_group_id, "name": "Test Floodlight Activity", } request = service.floodlightActivities().insert(profileId=profile_id, body=floodlight_activity) # Execute request and print response. response = request.execute() print('Created floodlight activity with ID %s and name "%s".' % (response["id"], response["name"])) except client.AccessTokenRefreshError: print("The credentials have been revoked or expired, please re-run the " "application to re-authorize")
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 campaign_id = flags.campaign_id creative_id = flags.creative_id try: # Construct the request. association = { 'creativeId': creative_id } request = service.campaignCreativeAssociations().insert( profileId=profile_id, campaignId=campaign_id, body=association) # Execute request and print response. response = request.execute() print ('Creative with ID %s is now associated with campaign %s.' % (response['creativeId'], campaign_id)) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 advertiser_id = str(flags.advertiser_id) list_id = flags.remarketing_list_id try: # Load the existing share info. share = service.remarketingListShares().get( profileId=profile_id, remarketingListId=list_id).execute() share['sharedAdvertiserIds'] = share.get('sharedAdvertiserIds', []) if advertiser_id not in share['sharedAdvertiserIds']: share['sharedAdvertiserIds'].append(advertiser_id) # Update the share info with the newly added advertiser ID. response = service.remarketingListShares().update( profileId=profile_id, body=share).execute() print ('Remarketing list %s is now shared to advertiser ID(s): %s.' % (list_id, ','.join(response['sharedAdvertiserIds']))) else: print ('Remarketing list %s is already shared to advertiser %s' % (list_id, advertiser_id)) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 height = flags.height width = flags.width try: # Construct the request. request = service.sizes().list(profileId=profile_id, height=height, width=width) # Execute request and print response. result = request.execute() for size in result['sizes']: print 'Found size with ID %s.' % (size['id']) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 advertiser_id = flags.advertiser_id try: # Construct and save campaign. campaign = { "name": "Test Campaign", "advertiserId": advertiser_id, "archived": "false", "startDate": "2015-01-01", "endDate": "2020-01-01", } request = service.campaigns().insert( profileId=profile_id, defaultLandingPageName="Test Landing Page", defaultLandingPageUrl="http://www.google.com", body=campaign, ) # Execute request and print response. response = request.execute() print('Created campaign with ID %s and name "%s".' % (response["id"], response["name"])) except client.AccessTokenRefreshError: print("The credentials have been revoked or expired, please re-run the " "application to re-authorize")
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 campaign_id = flags.campaign_id try: # Construct and save event tag. event_tag = { 'campaignId': campaign_id, 'name': 'Test Campaign Event Tag', 'status': 'ENABLED', 'type': 'CLICK_THROUGH_EVENT_TAG', 'url': 'https://www.google.com' } request = service.eventTags().insert(profileId=profile_id, body=event_tag) # Execute request and print response. response = request.execute() print ('Created campaign event tag with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 advertiser_id = flags.advertiser_id try: # Construct the request. request = service.floodlightActivityGroups().list( profileId=profile_id, advertiserId=advertiser_id) # Execute request and print response. response = request.execute() for group in response['floodlightActivityGroups']: print ('Found floodlight activity group with ID %s and name "%s".' % (group['id'], group['name'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 subaccount_id = flags.subaccount_id try: # Construct and execute the subaccount request. request = service.subaccounts().get( profileId=profile_id, id=subaccount_id) subaccount = request.execute() # Construct the user role permissions request. request = service.userRolePermissions().list( profileId=profile_id, ids=subaccount['availablePermissionIds']) # Execute request and print response. result = request.execute() for permission in result['userRolePermissions']: print ('Found user role permission with ID %s and name "%s".' % (permission['id'], permission['name'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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: # Create a new report resource to insert report = { 'name': 'Example Standard Report', 'type': 'STANDARD', 'criteria': { 'dateRange': {'relativeDateRange': 'YESTERDAY'}, 'dimensions': [{'name': 'dfa:campaign'}], 'metricNames': ['dfa:clicks'] } } # Construct the request. request = service.reports().insert(profileId=profile_id, body=report) # Execute request and print response. response = request.execute() print ('Created %s report with ID %s and name "%s".' % (response['type'], response['id'], response['name'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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: # 1. Create a report resource. report = create_report_resource() # 2. Define the report criteria. define_report_criteria(report) # 3. (optional) Look up compatible fields. find_compatible_fields(service, profile_id, report) # 4. Add dimension filters to the report criteria. add_dimension_filters(service, profile_id, report) # 5. Save the report resource. report = insert_report_resource(service, profile_id, report) except client.AccessTokenRefreshError: print('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 and save placement strategy. placement_strategy = { 'name': 'Test Strategy' } request = service.placementStrategies().insert( profileId=profile_id, body=placement_strategy) # Execute request and print response. response = request.execute() print ('Created placement strategy with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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: # Limit the fields returned fields = 'nextPageToken,targetingTemplates(advertiserId,id,name)' # Construct the request. request = service.targetingTemplates().list(profileId=profile_id, fields=fields) while True: # Execute request and print response. response = request.execute() for template in response['targetingTemplates']: print ('Found targeting template with ID %s and name "%s" associated ' 'with advertiser ID %s.' % (template['id'], template['name'], template['advertiserId'])) if response['targetingTemplates'] and response['nextPageToken']: request = service.targetingTemplates().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(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 activity_id = flags.activity_id try: # Construct the request. request = service.floodlightActivities().generatetag( profileId=profile_id, floodlightActivityId=activity_id) # Execute request and print response. response = request.execute() print response['floodlightActivityTag'] except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 activity_id = flags.activity_id try: # Construct the request. request = service.floodlightActivities().generatetag( profileId=profile_id, floodlightActivityId=activity_id) # Execute request and print response. response = request.execute() if 'globalSiteTagGlobalSnippet' in response: # Print both global snippet and event snippet. print('Global site tag global snippet:\n\n%s' % response['globalSiteTagGlobalSnippet']) print('\n\nGlobal site tag event snippet:\n\n%s' % response['floodlightActivityTag']) else: # Print the Floodlight activity tag. print('Floodlight activity tag:\n\n%s' % response['floodlightActivityTag']) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 floodlight_config_id = flags.floodlight_config_id try: # Construct and save floodlight activity group. activity_group = { 'name': 'Test Floodlight Activity Group', 'floodlightConfigurationId': floodlight_config_id, 'type': 'COUNTER' } request = service.floodlightActivityGroups().insert( profileId=profile_id, body=activity_group) # Execute request and print response. response = request.execute() print ('Created floodlight activity group with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 a get request for the specified profile. request = service.files().list(profileId=profile_id) while True: # Execute request and print response. response = request.execute() for report_file in response['items']: print ('File with ID %s and file name "%s" has status "%s".' % (report_file['id'], report_file['fileName'], report_file['status'])) if response['items'] and response['nextPageToken']: request = service.files().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(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 advertiser_id = flags.advertiser_id try: # Construct a landing page object. landing_page = { 'name': 'Test Landing Page #%s' % uuid.uuid4(), 'advertiserId': advertiser_id, 'archived': 'false', 'url': 'https://www.google.com' } request = service.advertiserLandingPages().insert( profileId=profile_id, body=landing_page) # Execute request and print response. response = request.execute() print('Created advertiser landing page with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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.subaccounts().list(profileId=profile_id) while True: # Execute request and print response. response = request.execute() for subaccount in response["subaccounts"]: print('Found subaccount with ID %s and name "%s".' % (subaccount["id"], subaccount["name"])) if response["subaccounts"] and response["nextPageToken"]: request = service.subaccounts().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(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 field_id = flags.field_id try: # Construct and save creative field value field_value = { 'value': 'Test Creative Field Value' } request = service.creativeFieldValues().insert( profileId=profile_id, creativeFieldId=field_id, body=field_value) # Execute request and print response. response = request.execute() print ('Created creative field value with ID %s and value "%s".' % (response['id'], response['value'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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: # Limit the fields returned fields = 'nextPageToken,userRoles(accountId,id,name,subaccountId)' # Construct the request. request = service.userRoles().list(profileId=profile_id, fields=fields) while True: # Execute request and print response. response = request.execute() for user_role in response['userRoles']: print ('Found user role with ID %s and name "%s".' % (user_role['id'], user_role['name'])) if response['userRoles'] and response['nextPageToken']: request = service.userRoles().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(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 report_id = flags.report_id try: # 1. Find a file to download. report_file = find_file(service, profile_id, report_id) if report_file: # 2. (optional) Generate browser URL. generate_browser_url(service, report_id, report_file['id']) # 3. Directly download the file. direct_download_file(service, report_id, report_file['id']) else: print 'No file found for profile ID %d and report ID %d.' % ( profile_id, report_id) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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: # 1. Find a report to run. report = find_report(service, profile_id) if report: # 2. Run the report. report_file = run_report(service, profile_id, report['id']) # 3. Wait for the report file to be ready. wait_for_report_file(service, report['id'], report_file['id']) else: print 'No report found for profile ID %d.\n' % profile_id except client.AccessTokenRefreshError: print('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 campaign_id = flags.campaign_id placement_id = flags.placement_id try: # Construct the request. request = service.placements().generatetags( profileId=profile_id, campaignId=campaign_id, placementIds=[placement_id] ) # Execute request and print response. response = request.execute() for placement_tag in response["placementTags"]: print_placement_tag(placement_tag) except client.AccessTokenRefreshError: print ("The credentials have been revoked or expired, please re-run the " "application to re-authorize")
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 report_id = flags.report_id try: # Retrieve the specified report resource report = service.reports().get( profileId=profile_id, reportId=report_id).execute() compatible_fields_type = get_compatible_fields_type(report['type']) # Construct the request request = service.reports().compatibleFields().query( profileId=profile_id, body=report) # Execute the request and print response. response = request.execute() compatible_fields = response[compatible_fields_type] print_fields('Dimensions', compatible_fields['dimensions']) print_fields('Metrics', compatible_fields['metrics']) print_fields('Dimension Filters', compatible_fields['dimensionFilters']) print_fields('Pivoted Activity Metrics', compatible_fields['pivotedActivityMetrics']) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 report_id = flags.report_id try: # Construct a get request for the specified report. request = service.reports().run(profileId=profile_id, reportId=report_id) # Execute request and print response. result = request.execute() print('Report file with ID %s is currently in status "%s".' % (result['id'], result['status'])) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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.ads().list(profileId=profile_id, active=True) while True: # Execute request and print response. response = request.execute() for ad in response['ads']: print ('Found ad with ID %s and name "%s".' % (ad['id'], ad['name'])) if response['ads'] and response['nextPageToken']: request = service.ads().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(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 advertiser_id = flags.advertiser_id try: # Construct and save creative group creative_group = { 'advertiserId': advertiser_id, 'groupNumber': 1, 'name': 'Test Creative Group' } request = service.creativeGroups().insert( profileId=profile_id, body=creative_group) # Execute request and print response. response = request.execute() print ('Created creative group with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 account_id = flags.account_id permission_id = flags.permission_id try: # Construct the basic subaccount structure. subaccount = { 'name': 'Test Subaccount', 'accountId': account_id, 'availablePermissionIds': [permission_id] } request = service.subaccounts().insert(profileId=profile_id, body=subaccount) # Execute request and print response. response = request.execute() print('Created subaccount with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 activity_group_id = flags.activity_group_id try: # Construct and save floodlight activity. floodlight_activity = { 'countingMethod': 'STANDARD_COUNTING', 'expectedUrl': 'http://www.google.com', 'floodlightActivityGroupId': activity_group_id, 'name': 'Test Floodlight Activity' } request = service.floodlightActivities().insert( profileId=profile_id, body=floodlight_activity) # Execute request and print response. response = request.execute() print('Created floodlight activity with ID %s and name "%s".' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 advertiser_id = flags.advertiser_id try: # Construct the request. request = service.floodlightActivities().list( profileId=profile_id, advertiserId=advertiser_id) while True: # Execute request and print response. response = request.execute() for activity in response['floodlightActivities']: print ('Found floodlight activity with ID %s and name "%s".' % (activity['id'], activity['name'])) if response['floodlightActivities'] and response['nextPageToken']: request = service.floodlightActivities().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(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: # 1. Find a report to run. report = find_report(service, profile_id) if report: # 2. Run the report. report_file = run_report(service, profile_id, report['id']) # 3. Wait for the report file to be ready. wait_for_report_file(service, report['id'], report_file['id']) else: print 'No report found for profile ID %d.\n' % profile_id except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 floodlight_activity_id = flags.floodlight_activity_id mobile_device_id = flags.mobile_device_id ordinal = flags.ordinal timestamp = flags.timestamp new_quantity = flags.new_quantity new_value = flags.new_value try: # Look up the Floodlight configuration ID based on activity ID. floodlight_activity = service.floodlightActivities().get( profileId=profile_id, id=floodlight_activity_id).execute() floodlight_config_id = floodlight_activity['floodlightConfigurationId'] # Construct the conversion object with values that identify the conversion # to update. conversion = { 'floodlightActivityId': floodlight_activity_id, 'floodlightConfigurationId': floodlight_config_id, 'ordinal': ordinal, 'mobileDeviceId': mobile_device_id, 'timestampMicros': timestamp } # Set the fields to be updated. These fields are required; to preserve a # value from the existing conversion, it must be copied over manually. conversion['quantity'] = new_quantity conversion['value'] = new_value # Update the conversion. request_body = {'conversions': [conversion]} request = service.conversions().batchupdate(profileId=profile_id, body=request_body) response = request.execute() if not response['hasFailures']: print('Successfully updated conversion for mobile device ID %s.' % mobile_device_id) else: print('Error(s) updating conversion for mobile device ID %s.' % mobile_device_id) status = response['status'][0] for error in status['errors']: print '\t[%s]: %s' % (error['code'], error['message']) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 campaign_id = flags.campaign_id placement_id = flags.placement_id creative_id = flags.creative_id try: # Retrieve the campaign (to get end date). campaign = service.campaigns().get(profileId=profile_id, id=campaign_id).execute() # Construct creative assignment. creative_assignment = { "active": "true", "creativeId": creative_id, "clickThroughUrl": {"defaultLandingPage": "true"}, } # Construct placement assignment. placement_assignment = {"active": "true", "placementId": placement_id} # Construct creative rotation. creative_rotation = { "creativeAssignments": [creative_assignment], "type": "CREATIVE_ROTATION_TYPE_RANDOM", "weightCalculationStrategy": "WEIGHT_STRATEGY_OPTIMIZED", } # Construct delivery schedule. delivery_schedule = {"impressionRatio": "1", "priority": "AD_PRIORITY_01"} # Construct and save ad. ad = { "active": "true", "campaignId": campaign_id, "creativeRotation": creative_rotation, "deliverySchedule": delivery_schedule, "endTime": "%sT00:00:00Z" % campaign["endDate"], "name": "Test Rotation Group", "placementAssignments": [placement_assignment], "startTime": "%sT23:59:59Z" % time.strftime("%Y-%m-%d"), "type": "AD_SERVING_STANDARD_AD", } request = service.ads().insert(profileId=profile_id, body=ad) # Execute request and print response. response = request.execute() print('Created rotation group with ID %s and name "%s".' % (response["id"], response["name"])) except client.AccessTokenRefreshError: print("The credentials have been revoked or expired, please re-run the " "application to re-authorize")
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) execution_date = flags.execution_date profile_id = DCM_PROFILE_ID report_id = DCM_REPORT_ID criteria = { "floodlightCriteria": { "dateRange": { "startDate": execution_date, "endDate": execution_date}}} try: #Update the date range update_date = service.reports().patch(profileId=profile_id,reportId=report_id,body=criteria).execute() # Run the report. report_file = service.reports().run(profileId=profile_id, reportId=report_id).execute() print('File with ID %s has been created.' % (report_file['id'])) # Wait for the report file to finish processing. # An exponential backoff strategy is used to conserve request quota. sleep = 0 start_time = time.time() while True: report_file = service.files().get(reportId=report_id, fileId=report_file['id']).execute() status = report_file['status'] if status == 'REPORT_AVAILABLE': print('File status is %s, ready to download.' % (status)) # 2. (optional) Generate browser URL. #generate_browser_url(service, report_id, report_file['id']) # 3. Directly download the file. direct_download_file(service, report_id, report_file['id']) return elif status != 'PROCESSING': print('File status is %s, processing failed.' % (status)) return elif time.time() - start_time > MAX_RETRY_ELAPSED_TIME: print('File processing deadline exceeded.') return sleep = next_sleep_interval(sleep) print('File status is %s, sleeping for %d seconds.' % (status, sleep)) time.sleep(sleep) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
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 advertiser_id = flags.advertiser_id activity_id = flags.activity_id try: # Create a list population term. # This term matches all visitors with a U1 value exactly matching # "test_value" term = { 'operator': 'STRING_EQUALS', 'type': 'CUSTOM_VARIABLE_TERM', 'value': 'test_value', 'variableName': 'U1' } # Add the term to a clause and the clause to a population rule. # This rule will target all visitors who trigger the specified floodlight # activity and satisfy the custom rule defined in the list population term. rule = { 'floodlightActivityId': activity_id, 'listPopulationClauses': { 'terms': [term] } } # Create the remarketing list. list = { 'name': 'Test Remarketing List', 'active': 'true', 'advertiserId': advertiser_id, 'lifeSpan': 30, 'listPopulationRule': rule } request = service.remarketingLists().insert(profileId=profile_id, body=list) # Execute request and print response. response = request.execute() print('Created remarketing list with ID %s and name "%s."' % (response['id'], response['name'])) except client.AccessTokenRefreshError: print( 'The credentials have been revoked or expired, please re-run the ' 'application to re-authorize')
def main(argv): flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) # retrieve command line arguments global cfg with open("config.yml", 'r') as ymlfile: cfg = yaml.safe_load(ymlfile) # find and read config file cfg = struct(**cfg) try: conn = psycopg2.connect(database=cfg.postgres['database'], user=cfg.postgres['username'], password=cfg.postgres['password'], host=cfg.postgres['host'], port=cfg.postgres['port']) except: raise else: print "Opened database successfully" # authenticate and construct service service = dfareporting_utils.setup(flags) profile_id = cfg.dcm['profile_id'] report_id = flags.report_id try: # construct a get request for the specified report request = service.reports().run(profileId=profile_id, reportId=report_id) result = request.execute() file_id = result['id'] # check status of report file request = service.reports().files().list(profileId=profile_id, reportId=report_id) response = request.execute() while response['items'][0]['status'] != 'REPORT_AVAILABLE': print 'Report/File IDs: ', report_id, ': ', file_id, ': ', response['items'][0][ 'status'], '\nWaiting for report to generate...' sleep(30) # delay for 30 seconds before checking again request = service.reports().files().list(profileId=profile_id, reportId=report_id) response = request.execute() print 'Report/File IDs: ', report_id, ': ', file_id, ': ', response['items'][0]['status'] print 'Browser: ', response['items'][0]['urls']['browserUrl'] print 'API: ', response['items'][0]['urls']['apiUrl'] request = service.files().get_media(reportId=report_id, fileId=file_id) # construct request to download file report_file = request.execute() csv_data = reader(report_file.splitlines(), delimiter=',') load_data(csv_data, conn, cfg.postgres['table_schema'], cfg.postgres['insert_table']) except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run the application to re-authorize') conn.close() print '\n**********DONE**********\n'