__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. from datetime import date import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) client.strict = False # Initialize appropriate service. forecast_service = client.GetService('ForecastService', version='v201306') # Set the placement that the prospective line item will target. target_placement_ids = ['INSERT_PLACEMENT_ID_HERE'] # Create prospective line item. line_item = { 'targeting': { 'inventoryTargeting': { 'targetedPlacementIds': target_placement_ids } },
get_all_custom_targeting_keys_and_values.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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. custom_targeting_service = client.GetService( 'CustomTargetingService', version='v201306') key_id = 'INSERT_CUSTOM_TARGETING_VALUE_ID_HERE' values = [{ 'key': 'keyId', 'value': { 'xsi_type': 'NumberValue', 'value': key_id } }] filter_statement = {'query': 'WHERE customTargetingKeyId = :keyId LIMIT 500', 'values': values}
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='v201206') # 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)
__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.common import Utils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. placement_service = client.GetService('PlacementService', version='v201211') inventory_service = client.GetService('InventoryService', version='v201211') # Create placement object to store medium rectangle ad units. medium_rectangle_ad_unit_placement = { 'name': 'Medium rectangle AdUnit Placement #%s' % Utils.GetUniqueName(), 'description': 'Contains ad units that can hold creatives of size 300x250', 'targetedAdUnitIds': [] } # Create placement object to store skyscraper ad units. skyscraper_ad_unit_placement = { 'name': 'Skyscraper AdUnit Placement #%s' % Utils.GetUniqueName(),
get_all_orders.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.common import Utils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..', '..')) # Initialize appropriate service. order_service = client.GetService('OrderService', version='v201311') # Set advertiser (company), salesperson, and trafficker to assign to each order. advertiser_id = 'INSERT_ADVERTISER_COMPANY_ID_HERE' salesperson_id = 'INSERT_SALESPERSON_ID_HERE' trafficker_id = 'INSERT_TRAFFICKER_ID_HERE' # Create order objects. orders = [] for i in xrange(5): order = { 'name': 'Order #%s' % Utils.GetUniqueName(), 'advertiserId': advertiser_id,
__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='v201206') query = 'WHERE numRequests >= :numRequests' values = [{ 'key': 'numRequests', 'value': { 'xsi_type': 'NumberValue', 'value': '50' } }] suggested_ad_units = DfpUtils.GetAllEntitiesByStatementWithService(
print('Log in to your DFP account and open the following URL: \n%s\n' % authorize_url) print 'After approving the token enter the verification code (if specified).' code = raw_input('Code: ').strip() credential = None try: credential = flow.step2_exchange(code) except FlowExchangeError, e: sys.exit('Authentication has failed: %s' % e) # Create the DfpClient and set the OAuth2 credentials. client = DfpClient( headers={ 'networkCode': network_code, 'applicationName': application_name, 'userAgent': 'OAuth2 Example', 'oauth2credentials': credential }) # OAuth2 credentials objects can be reused credentials = client.oauth2credentials print 'OAuth2 authorization successful!' # OAuth2 credential objects can be refreshed via credentials.refresh() - the # access token expires after 1 hour. credentials.refresh(httplib2.Http()) # Note: you could simply set the credentials as below and skip the previous # steps once access has been granted. client.oauth2credentials = credentials
Tags: TeamService.getTeam """ __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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. team_service = client.GetService('TeamService', version='v201308') # Set the ID of the team to get. team_id = 'INSERT_TEAM_ID_HERE' # Get team. team = team_service.GetTeam(team_id)[0] # Display results. print('Team with ID \'%s\' and name \'%s\' was found.' % (team['id'], team['name']))
line items, run create_line_items.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 datetime import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. line_item_service = client.GetService('LineItemService', 'https://www.google.com', 'v201203') order_id = 'INSERT_ORDER_ID_HERE' # Create statement object to only select line items belonging to the order and # have been modified in the last 3 days. three_days_ago = datetime.date.today() - datetime.timedelta(days=3) values = [{ 'key': 'dateTimeString', 'value': { 'xsi_type': 'TextValue', 'value': three_days_ago.strftime('%Y-%m-%dT%H:%M:%S')
get_all_custom_targeting_keys_and_values.py. To target these custom targeting keys and values, run target_custom_criteria_example.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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. custom_targeting_service = client.GetService('CustomTargetingService', 'https://www.google.com', 'v201203') # Create custom targeting key objects. keys = [ { 'displayName': 'gender', 'name': 'g', 'type': 'PREDEFINED' }, { 'displayName': 'car model',
run get_all_placements.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. from datetime import date import os import sys sys.path.insert(0, os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle import DfpClient # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) client.strict = False # Initialize appropriate service. forecast_service = client.GetService('ForecastService', version='v201204') # Set the placement that the prospective line item will target. target_placement_ids = ['INSERT_PLACEMENT_ID_HERE'] # Create prospective line item. line_item = { 'targeting': { 'inventoryTargeting': { 'targetedPlacementIds': target_placement_ids } },
maximum page size limit of 500. To create an image creative, run 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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. creative_service = client.GetService('CreativeService', 'https://www.google.com', 'v201203') # Create statement object to only select image creatives. values = [{ 'key': 'creativeType', 'value': { 'xsi_type': 'TextValue', 'value': 'ImageCreative' } }] filter_statement = { 'query': 'WHERE creativeType = :creativeType LIMIT 500',
__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. audience_segment_service = client.GetService('AudienceSegmentService', version='v201206') # 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
__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.common import Utils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. placement_service = client.GetService( 'PlacementService', 'https://www.google.com', 'v201203') inventory_service = client.GetService( 'InventoryService', 'https://www.google.com', 'v201203') # Create placement object to store medium rectangle ad units. medium_rectangle_ad_unit_placement = { 'name': 'Medium rectangle AdUnit Placement #%s' % Utils.GetUniqueName(), 'description': 'Contains ad units that can hold creatives of size 300x250', 'targetedAdUnitIds': [] } # Create placement object to store skyscraper 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.common import Utils # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. creative_template_service = client.GetService( 'CreativeTemplateService', version='v201302') # Set id of the creative to get. creative_template_id = 'CREATIVE_TEMPLATE_ID_HERE' # Get creative. template = creative_template_service.getCreativeTemplate( creative_template_id)[0] # Display results. print ('Creative template with id \'%s\', name \'%s\', and type \'%s\' was ' 'found.') % (template['id'], template['name'], template['type'])
"""This code example gets all teams. To create teams, run create_teams.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. team_service = client.GetService('TeamService', 'https://www.google.com', 'v201203') # 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)
"""This code example updates the first third party slot's description.""" __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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. third_party_slot_service = client.GetService('ThirdPartySlotService', version='v201211') # Create statement object to only select third party slots that are active. values = [{ 'key': 'status', 'value': { 'xsi_type': 'TextValue', 'value': 'ACTIVE' } }] filter_statement = { 'query': 'WHERE status = :status LIMIT 1',
""" __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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. user_team_association_service = client.GetService( 'UserTeamAssociationService', version='v201208') # Set the user to set to read only access within its teams. 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 }
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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. label_service = client.GetService('LabelService', version='v201204') # Create label objects. labels = [] for i in xrange(5): label = { 'name': 'Label #%d' % i, 'isActive': 'True', 'types': ['COMPETITIVE_EXCLUSION'] } labels.append(label) # Add Labels.
__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='v201204') # 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)
# limitations under the License. """This code example gets a user by its id. To create users, run create_user.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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. user_service = client.GetService('UserService', version='v201204') # Set the id of the user to get. user_id = 'INSERT_USER_ID_HERE' # Get user. user = user_service.GetUser(user_id)[0] # Display results. print('User with id \'%s\', email \'%s\', and role \'%s\' was found.' % (user['id'], user['email'], user['roleName']))
download the report run download_report.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 time # Import appropriate classes from the client library. from adspygoogle import DfpClient # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. report_service = client.GetService('ReportService', 'https://www.google.com', 'v201203') order_id = 'INSERT_ORDER_ID_HERE' # Create statement object to filter for an order. values = [{ 'key': 'id', 'value': { 'xsi_type': 'NumberValue', 'value': order_id } }]
create_third_party_slot.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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. third_party_slot_service = client.GetService( 'ThirdPartySlotService', 'https://www.google.com', 'v201203') # Create a statement to only select archived third party slots. values = [{ 'key': 'status', 'value': { 'xsi_type': 'TextValue', 'value': 'ARCHIVED' } }] filter_statement = {'query': 'WHERE status = :status LIMIT 500', 'values': values}
LICAs exist, run get_all_licas.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. lica_service = client.GetService('LineItemCreativeAssociationService', version='v201302') # Set the id of the line item in which to deactivate LICAs. line_item_id = 'INSERT_LINE_ITEM_ID_HERE' # Create query. values = [{ 'key': 'lineItemId', 'value': { 'xsi_type': 'NumberValue', 'value': line_item_id }
order. The statement retrieves up to the maximum page size limit of 500. To create line items, run create_line_items.py.""" __author__ = ('Jeff Sham', '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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..', '..')) # Initialize appropriate service. line_item_service = client.GetService('LineItemService', version='v201308') # Set the id of the order to get line items from. order_id = 'INSERT_ORDER_ID_HERE' # Create statement object to only select line items that need creatives from a # given order. values = [{ 'key': 'orderId', 'value': { 'xsi_type': 'NumberValue', 'value': order_id }
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.' if __name__ == '__main__': # Initialize client object. dfp_client = DfpClient(path=os.path.join('..', '..', '..', '..', '..')) # Get the Network Service. network_service = dfp_client.GetService('NetworkService', version='v201211') # Set the parent ad unit's ID for all children ad units to be fetched from. root_id = network_service.GetCurrentNetwork()[0]['effectiveRootAdUnitId'] main(dfp_client, root_id)
"""This code example gets a forecast for an existing line item. To determine which ine items exist, run get_all_line_items.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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. forecast_service = client.GetService('ForecastService', version='v201211') # Set the line item to get a forecast for. line_item_id = 'INSERT_LINE_ITEM_ID' # Get forecast for line item. forecast = forecast_service.GetForecastById(line_item_id)[0] matched = long(forecast['matchedUnits']) available_percent = (long(forecast['availableUnits']) / (matched * 1.0)) * 100 # Display results. print('%s %s matched.\n%s%% %s available.' % (matched, forecast['unitType'].lower(), available_percent,
DFP 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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. content_service = client.GetService('ContentService', version='v201204') network_service = client.GetService('NetworkService', version='v201204') custom_targeting_service = client.GetService( 'CustomTargetingService', version='v201204') # Get the network's content browse custom targeting key. network = network_service.GetCurrentNetwork()[0] key_id = network['contentBrowseCustomTargetingKeyId'] # Create a statement to select the categories matching the name comedy. values = [
# Initialize appropriate service. custom_field_service = client.GetService('CustomFieldService', version='v201311') # Get custom field. custom_field = custom_field_service.GetCustomField(custom_field_id)[0] if custom_field: custom_field['description'] += ' Updated.' # Update the custom field on the server. custom_fields = custom_field_service.UpdateCustomFields([custom_field]) # Display results. if custom_fields: for custom_field in custom_fields: print(('Custom field with ID \'%s\', name \'%s\', and ' 'description \'%s\' was updated.') % (custom_field['id'], custom_field['name'], custom_field['description'])) else: print 'No custom fields were updated.' else: print 'No custom fields found to update.' if __name__ == '__main__': # Initialize client object. dfp_client = DfpClient(path=os.path.join('..', '..', '..', '..', '..')) main(dfp_client, CUSTOM_FIELD_ID)
__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 time # Import appropriate classes from the client library. from adspygoogle import DfpClient # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. report_service = client.GetService('ReportService', version='v201211') # Create report job. report_job = { 'reportQuery': { 'dimensions': ['ORDER'], 'columns': [ 'MERGED_AD_SERVER_IMPRESSIONS', 'MERGED_AD_SERVER_CLICKS', 'MERGED_AD_SERVER_CTR', 'MERGED_AD_SERVER_CPM_AND_CPC_REVENUE', 'MERGED_AD_SERVER_AVERAGE_ECPM' ], 'dateRangeType': 'LAST_MONTH'
print ('Log in to your DFP account and open the following URL: \n%s\n' % authorize_url) print 'After approving the token enter the verification code (if specified).' code = raw_input('Code: ').strip() credential = None try: credential = flow.step2_exchange(code) except FlowExchangeError, e: sys.exit('Authentication has failed: %s' % e) # Create the DfpClient and set the OAuth2 credentials. client = DfpClient(headers={ 'networkCode': network_code, 'applicationName': application_name, 'userAgent': 'OAuth2 Example', 'oauth2credentials': credential }) # OAuth2 credentials objects can be reused credentials = client.oauth2credentials print 'OAuth2 authorization successful!' # OAuth2 credential objects can be refreshed via credentials.refresh() - the # access token expires after 1 hour. credentials.refresh(httplib2.Http()) # Note: you could simply set the credentials as below and skip the previous # steps once access has been granted. client.oauth2credentials = credentials
associations (LICA) up to the first 500. To determine which LICAs exist, run get_all_licas.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 # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. lica_service = client.GetService('LineItemCreativeAssociationService', 'https://www.google.com', 'v201203') # Create statement object to get all LICAs. filter_statement = {'query': 'LIMIT 500'} # Get LICAs by statement. response = lica_service.GetLineItemCreativeAssociationsByStatement( filter_statement)[0] licas = [] if 'results' in response: licas = response['results']