def main(client): # Initialize appropriate service. inventory_service = client.GetService('InventoryService', version='v201308') # Get ad units by statement. all_ad_units = DfpUtils.GetAllEntitiesByStatementWithService( inventory_service) # Find the root ad unit. root_ad_unit can also be set to child unit to only # build and display a portion of the tree. # i.e. root_ad_unit = inventory_service.GetAdUnit('INSERT_AD_UNIT_HERE')[0] response = DfpUtils.GetAllEntitiesByStatementWithService( inventory_service, query='WHERE parentId IS NULL') root_ad_unit = {} if response: root_ad_unit = response[0] if root_ad_unit: BuildAndDisplayAdUnitTree(response[0], all_ad_units) else: print 'Could not build tree. No root ad unit found.'
def main(client): # Initialize appropriate service. company_service = client.GetService('CompanyService', version='v201208') # Get companies by statement. companies = DfpUtils.GetAllEntitiesByStatementWithService(company_service) # Display results. for company in companies: print ('Company with ID \'%s\', name \'%s\', and type \'%s\' was found.' % (company['id'], company['name'], company['type'])) print print 'Number of results found: %s' % len(companies)
def main(client): # Initialize appropriate service. contact_service = client.GetService('ContactService', version='v201302') # Get contacts by statement. contacts = DfpUtils.GetAllEntitiesByStatementWithService(contact_service) # Display results. for contact in contacts: print('Contact with ID \'%s\' and name \'%s\' was found.' % (contact['id'], contact['name'])) print print 'Number of results found: %s' % len(contacts)
def main(client): # Initialize appropriate service. custom_field_service = client.GetService('CustomFieldService', version='v201308') # Create statement to select only active custom fields that apply to # line items. values = [{ 'key': 'entityType', 'value': { 'xsi_type': 'TextValue', 'value': 'LINE_ITEM' } }, { 'key': 'isActive', 'value': { 'xsi_type': 'BooleanValue', 'value': 'true' } }] query = 'WHERE entityType = :entityType and isActive = :isActive' # Get custom fields by statement. custom_fields = DfpUtils.GetAllEntitiesByStatementWithService( custom_field_service, query=query, bind_vars=values) # Display results. for custom_field in custom_fields: print( 'Custom field with ID \'%s\' and name \'%s\' will be deactivated.' % (custom_field['id'], custom_field['name'])) print print 'Number of custom fields to be deactivated: %s' % len(custom_fields) if custom_fields: # Perform action. result = custom_field_service.PerformCustomFieldAction( {'type': 'DeactivateCustomFields'}, { 'query': query, 'values': values })[0] # Display results. if result and int(result['numChanges']) > 0: print 'Number of custom fields deactivated: %s' % result[ 'numChanges'] else: print 'No custom fields were deactivated.'
def main(client): # Initialize appropriate service. activity_group_service = client.GetService('ActivityGroupService', version='v201308') # Get activity groups by statement. activity_groups = DfpUtils.GetAllEntitiesByStatementWithService( activity_group_service) # Display results. for activity_group in activity_groups: print('Activity group with ID \'%s\' and name \'%s\' was found.' % (activity_group['id'], activity_group['name'])) print print 'Number of results found: %s' % len(activity_groups)
def main(client, label_id): # Initialize appropriate service. creative_wrapper_service = client.GetService('CreativeWrapperService', version='v201308') # Create a query to select the active creative wrappers for the given label. values = [{ 'key': 'labelId', 'value': { 'xsi_type': 'NumberValue', 'value': label_id } }, { 'key': 'status', 'value': { 'xsi_type': 'TextValue', 'value': 'ACTIVE' } }] query = 'WHERE status = :status AND labelId = :labelId' # Get creative wrapper by statement. creative_wrappers = DfpUtils.GetAllEntitiesByStatementWithService( creative_wrapper_service, query=query, bind_vars=values) for creative_wrapper in creative_wrappers: print( 'Creative wrapper with ID \'%s\' applying to label \'%s\' with ' 'status \'%s\' will be deactivated.' % (creative_wrapper['id'], creative_wrapper['labelId'], creative_wrapper['status'])) print('Number of creative wrappers to be deactivated: %s' % len(creative_wrappers)) # Perform action. result = creative_wrapper_service.PerformCreativeWrapperAction( {'type': 'DeactivateCreativeWrappers'}, { 'query': query, 'values': values })[0] # Display results. if result and int(result['numChanges']) > 0: print 'Number of creative wrappers deactivated: %s' % result[ 'numChanges'] else: print 'No creative wrappers were deactivated.'
def main(client): # Initialize appropriate service. creative_wrapper_service = client.GetService('CreativeWrapperService', version='v201211') # Get creative wrappers by statement. creative_wrappers = DfpUtils.GetAllEntitiesByStatementWithService( creative_wrapper_service) # Display results. for creative_wrapper in creative_wrappers: print( 'Creative wrapper with ID \'%s\' applying to label \'%s\' was found.' % (creative_wrapper['id'], creative_wrapper['labelId'])) print print 'Number of results found: %s' % len(creative_wrappers)
def testGetAllEntitiesByStatementWithService(self): line_item_service = mock.Mock() rval = 'Line items for everyone!' def VerifyExpectedCall(arg): self.assertEqual( { 'values': None, 'query': 'ORDER BY name LIMIT 500 OFFSET 0' }, arg) return [{'results': [rval]}] line_item_service._service_name = 'LineItemService' line_item_service.GetLineItemsByStatement.side_effect = VerifyExpectedCall line_items = DfpUtils.GetAllEntitiesByStatementWithService( line_item_service, 'ORDER BY name') self.assertEqual([rval], line_items)
def GetAllActivityGroupIds(client): """Gets all activity group IDs.""" activity_group_ids = [] # Initialize appropriate service. activity_group_service = client.GetService('ActivityGroupService', version='v201302') # Get activity groups by statement. activity_groups = DfpUtils.GetAllEntitiesByStatementWithService( activity_group_service) # Display results. for activity_group in activity_groups: activity_group_ids.append(activity_group['id']) return activity_group_ids
def main(client): # Initialize appropriate service. creative_set_service = client.GetService('CreativeSetService', version='v201308') # Get creative sets by statement. creative_sets = DfpUtils.GetAllEntitiesByStatementWithService( creative_set_service) # Display results. for creative_set in creative_sets: print(('Creative set with ID \'%s\', master creative ID \'%s\', and ' 'companion creative IDs {%s} was found.') % (creative_set['id'], creative_set['masterCreativeId'], ','.join( creative_set['companionCreativeIds']))) print print 'Number of results found: %s' % len(creative_sets)
def main(client, parent_id): # Initialize appropriate service. inventory_service = client.GetService('InventoryService', version='v201204') # Create a query to select ad units under the parent ad unit and the parent ad # unit. values = [{ 'key': 'parentId', 'value': { 'xsi_type': 'NumberValue', 'value': parent_id } }] query = 'WHERE parentId = :parentId or id = :parentId' # Get ad units by statement. ad_units = DfpUtils.GetAllEntitiesByStatementWithService(inventory_service, query=query, bind_vars=values) for ad_unit in ad_units: print('Ad unit with ID \'%s\' and name \'%s\' will be archived.' % (ad_unit['id'], ad_unit['name'])) print 'Number of ad units to be archived: %s' % len(ad_units) # Perform action. result = inventory_service.PerformAdUnitAction({'type': 'ArchiveAdUnits'}, { 'query': query, 'values': values })[0] # Display results. if result and int(result['numChanges']) > 0: print 'Number of ad units archived: %s' % result['numChanges'] else: print 'No ad units were archived.'
networks.""" __author__ = '[email protected] (Jeff Sham)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. label_service = client.GetService('LabelService', version='v201308') # Get label by statement. labels = DfpUtils.GetAllEntitiesByStatementWithService(label_service) # Display results. for label in labels: print('Label with id \'%s\', name \'%s\', and types {%s} was found.' % (label['id'], label['name'], ','.join(label['types']))) print print 'Number of results found: %s' % len(labels)
# the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..', '..')) # Initialize appropriate service. activity_service = client.GetService('ActivityService', version='v201311') # Create a query to order activities by ascending IDs. query = 'ORDER BY Id ASC' # Get activities by statement. activities = DfpUtils.GetAllEntitiesByStatementWithService(activity_service, query=query) # Display results. for activity in activities: print( 'Activity with ID \'%s\', name \'%s\', and type \'%s\' was ' 'found.' % (activity['id'], activity['name'], activity['type'])) print print 'Number of results found: %s' % len(activities)
create_creatives.py.""" __author__ = '[email protected] (Jeff Sham)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. creative_service = client.GetService('CreativeService', version='v201204') # Get creatives by statement. creatives = DfpUtils.GetAllEntitiesByStatementWithService(creative_service) # Display results. for creative in creatives: print('Creative with id \'%s\', name \'%s\', and type \'%s\' was found.' % (creative['id'], creative['name'], creative['Creative_Type'])) print print 'Number of results found: %s' % len(creatives)
sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. lica_service = client.GetService( 'LineItemCreativeAssociationService', version='v201302') # Get LICAs by statement. licas = DfpUtils.GetAllEntitiesByStatementWithService(lica_service) # Display results. for lica in licas: if 'creativeSetId' in lica: print ('LICA with line item ID \'%s\', creative set ID \'%s\', and status ' '\'%s\' was found.' % (lica['lineItemId'], lica['creativeSetId'], lica['status'])) else: print ('LICA with line item ID \'%s\', creative ID \'%s\', and status ' '\'%s\' was found.' % (lica['lineItemId'], lica['creativeId'], lica['status'])) print print 'Number of results found: %s' % len(licas)
__author__ = '[email protected] (Jeff Sham)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. placement_service = client.GetService('PlacementService', version='v201208') # Get placements by statement. placements = DfpUtils.GetAllEntitiesByStatementWithService(placement_service) # Display results. for placement in placements: print ('Placement with id \'%s\' and name \'%s\' was found.' % (placement['id'], placement['name'])) print print 'Number of results found: %s' % len(placements)
__author__ = '[email protected] (Jeff Sham)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. user_service = client.GetService('UserService', 'https://www.google.com', 'v201203') # Get users by statement. users = DfpUtils.GetAllEntitiesByStatementWithService(user_service) # Display results. for user in users: print('User with id \'%s\', email \'%s\', and role \'%s\' was found.' % (user['id'], user['email'], user['roleName'])) print print 'Number of results found: %s' % len(users)
__author__ = '[email protected] (Jeff Sham)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. inventory_service = client.GetService('InventoryService', 'https://www.google.com', 'v201203') # Get ad units by statement. ad_units = DfpUtils.GetAllEntitiesByStatementWithService(inventory_service) # Display results. for ad_unit in ad_units: print('Ad unit with id \'%s\', name \'%s\', and status \'%s\' was found.' % (ad_unit['id'], ad_unit['name'], ad_unit['status'])) print print 'Number of results found: %s' % len(ad_units)
__author__ = '[email protected] (Jeff Sham)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. third_part_slot_service = client.GetService('ThirdPartySlotService', version='v201204') # Get third part slots by statement. third_part_slots = DfpUtils.GetAllEntitiesByStatementWithService( third_part_slot_service) # Display results. for third_part_slot in third_part_slots: print 'Third party slot with id \'%s\' was found.' % third_part_slot['id'] print print 'Number of results found: %s' % len(third_part_slots)
# Initialize appropriate service. inventory_service = client.GetService( 'InventoryService', 'https://www.google.com', 'v201203') # Create query. values = [{ 'key': 'status', 'value': { 'xsi_type': 'TextValue', 'value': 'ACTIVE' } }] query = 'WHERE status = :status' # Get ad units by statement. ad_units = DfpUtils.GetAllEntitiesByStatementWithService( inventory_service, query=query, bind_vars=values) for ad_unit in ad_units: print ('Ad unit with id \'%s\', name \'%s\', and status \'%s\' will be ' 'deactivated.' % (ad_unit['id'], ad_unit['name'], ad_unit['status'])) print 'Number of ad units to be deactivated: %s' % len(ad_units) # Perform action. result = inventory_service.PerformAdUnitAction( {'type': 'DeactivateAdUnits'}, {'query': query, 'values': values})[0] # Display results. if result and int(result['numChanges']) > 0: print 'Number of ad units deactivated: %s' % result['numChanges'] else: print 'No ad units were deactivated.'
""" __author__ = '[email protected] (Jeff Sham)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. team_service = client.GetService('TeamService', version='v201306') # Get team by statement. teams = DfpUtils.GetAllEntitiesByStatementWithService(team_service) # Display results. for team in teams: print('Team with ID \'%s\' and name \'%s\' was found.' % (team['id'], team['name'])) print print 'Number of results found: %s' % len(teams)
'key': 'status', 'value': { 'xsi_type': 'TextValue', 'value': 'ACTIVE' } }, { 'key': 'companyId', 'value': { 'xsi_type': 'NumberValue', 'value': company_id } }] query = 'WHERE status = :status and companyId = :companyId' # Get third party slots by statement. third_party_slots = DfpUtils.GetAllEntitiesByStatementWithService( third_party_slot_service, query=query, bind_vars=values) for third_party_slot in third_party_slots: print('Third party slot with id \'%s\' will be archived.' % third_party_slot['id']) print('Number of third party slots to be archived: %s' % len(third_party_slots)) # Perform action. result = third_party_slot_service.PerformThirdPartySlotAction( {'type': 'ArchiveThirdPartySlots'}, { 'query': query, 'values': values })[0]
# Set the id of the user to deactivate. user_id = 'INSERT_USER_ID_HERE' # Create query. values = [{ 'key': 'userId', 'value': { 'xsi_type': 'NumberValue', 'value': user_id } }] query = 'WHERE id = :userId' # Get users by statement. users = DfpUtils.GetAllEntitiesByStatementWithService(user_service, query=query, bind_vars=values) for user in users: print( 'User with id \'%s\', email \'%s\', and status \'%s\' will be ' 'deactivated.' % (user['id'], user['email'], { 'true': 'ACTIVE', 'false': 'INACTIVE' }[user['isActive']])) print 'Number of users to be deactivated: %s' % len(users) # Perform action. result = user_service.PerformUserAction({'type': 'DeactivateUsers'}, { 'query': query, 'values': values
client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. suggested_ad_unit_service = client.GetService('SuggestedAdUnitService', version='v201306') query = 'WHERE numRequests >= :numRequests' values = [{ 'key': 'numRequests', 'value': { 'xsi_type': 'NumberValue', 'value': '50' } }] suggested_ad_units = DfpUtils.GetAllEntitiesByStatementWithService( suggested_ad_unit_service, query=query, bind_vars=values) # Print suggested ad units that will be approved. for suggested_ad_unit in suggested_ad_units: print( 'Suggested ad unit with id \'%s\', and number of requests \'%s\' will' ' be approved.' % (suggested_ad_unit['id'], suggested_ad_unit['numRequests'])) print 'Number of suggested ad units to approve: %s' % len(suggested_ad_units) # Approve suggested ad units. result = suggested_ad_unit_service.performSuggestedAdUnitAction( {'type': 'ApproveSuggestedAdUnit'}, { 'query': query, 'values': values })[0]
# Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. audience_segment_service = client.GetService('AudienceSegmentService', version='v201306') # Get all audience segments. audience_segments = DfpUtils.GetAllEntitiesByStatementWithService( audience_segment_service) # Display results. for audience_segment in audience_segments: print('Audience segment with id \'%s\' and name \'%s\' was found.' % (audience_segment['id'], audience_segment['name'])) print print 'Number of results found: %s' % len(audience_segments)
'Vincent Tsao') # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..', '..')) # Initialize appropriate service. line_item_service = client.GetService('LineItemService', version='v201311') # Get line items by statement. line_items = DfpUtils.GetAllEntitiesByStatementWithService(line_item_service) # Display results. for line_item in line_items: print ('Line item with id \'%s\', belonging to order id \'%s\', and named ' '\'%s\' was found.' % (line_item['id'], line_item['orderId'], line_item['name'])) print print 'Number of results found: %s' % len(line_items)
video publishers.""" __author__ = '[email protected] (Jeff Sham)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. content_service = client.GetService('ContentService', version='v201308') # Get content by statement. content = DfpUtils.GetAllEntitiesByStatementWithService(content_service) # Display results. for content_item in content: print('Content with id \'%s\', name \'%s\', and status \'%s\' was found.' % (content_item['id'], content_item['name'], content_item['status'])) print print 'Number of results found: %s' % len(content)
version='v201311') user_id = 'INSERT_USER_ID_HERE' # Create filter text to select user team associations by the user ID. values = [{ 'key': 'userId', 'value': { 'xsi_type': 'NumberValue', 'value': user_id } }] query = 'WHERE userId = :userId' # Get user team associations by statement. user_team_associations = DfpUtils.GetAllEntitiesByStatementWithService( user_team_association_service, query=query, bind_vars=values) for user_team_association in user_team_associations: print( 'User team association between user with ID \'%s\' and team with ' 'ID \'%s\' will be deleted.' % (user_team_association['userId'], user_team_association['teamId'])) print('Number of teams that the user will be removed from: %s' % len(user_team_associations)) # Perform action. result = user_team_association_service.PerformUserTeamAssociationAction( {'type': 'DeleteUserTeamAssociations'}, { 'query': query, 'values': values })[0]
# Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. user_team_association_service = client.GetService('UserTeamAssociationService', version='v201208') # Get the user team associations by statement. user_team_associations = DfpUtils.GetAllEntitiesByStatementWithService( user_team_association_service) # Display results. for user_team_association in user_team_associations: print( 'User team association between user with ID \'%s\' and team with ID ' '\'%s\' was found.' % (user_team_association['userId'], user_team_association['teamId'])) print print 'Number of results found: %s' % len(user_team_associations)
solution networks.""" __author__ = '[email protected] (Jeff Sham)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient from adspygoogle.dfp import DfpUtils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. suggested_ad_unit_service = client.GetService('SuggestedAdUnitService', version='v201302') # Get suggested ad units. suggested_ad_units = DfpUtils.GetAllEntitiesByStatementWithService( suggested_ad_unit_service) # Display results. for suggested_ad_unit in suggested_ad_units: print('Suggested ad unit with id \'%s\' and number of requests \'%s\' was' ' found.' % (suggested_ad_unit['id'], suggested_ad_unit['numRequests']))