def authenticate(authorization_data): # import logging # logging.basicConfig(level=logging.INFO) # logging.getLogger('suds.client').setLevel(logging.DEBUG) # logging.getLogger('suds.transport.http').setLevel(logging.DEBUG) customer_service = ServiceClient( 'CustomerManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=11, ) # You should authenticate for Bing Ads services with a Microsoft Account, # instead of providing the Bing Ads username and password set. authenticate_with_oauth(authorization_data) # Bing Ads API Version 11 is the last version to support UserName and Password authentication, # so this method is deprecated. #authenticate_with_username(authorization_data) # Set to an empty user identifier to get the current authenticated Bing Ads user, # and then search for all accounts the user may access. user = customer_service.GetUser(None).User accounts = search_accounts_by_user_id(customer_service, user.Id) # For this example we'll use the first account. authorization_data.account_id = accounts['Account'][0].Id authorization_data.customer_id = accounts['Account'][0].ParentCustomerId
def authenticate(authorization_data): # import logging # logging.basicConfig(level=logging.INFO) # logging.getLogger('suds.client').setLevel(logging.DEBUG) # logging.getLogger('suds.transport.http').setLevel(logging.DEBUG) customer_service = ServiceClient( 'CustomerManagementService', version=12, authorization_data=authorization_data, environment=ENVIRONMENT, ) # You should authenticate for Bing Ads services with a Microsoft Account. authenticate_with_oauth(authorization_data) # Set to an empty user identifier to get the current authenticated Bing Ads user, # and then search for all accounts the user can access. user = customer_service.GetUser(None).User accounts = search_accounts_by_user_id(customer_service, user.Id) # For this example we'll use the first account. authorization_data.account_id = accounts['AdvertiserAccount'][0].Id authorization_data.customer_id = accounts['AdvertiserAccount'][ 0].ParentCustomerId
def authenticate(authorization_data): #import logging #logging.basicConfig(level=logging.INFO) #logging.getLogger('suds.client').setLevel(logging.DEBUG) #logging.getLogger('suds.transport.http').setLevel(logging.DEBUG) customer_service = ServiceClient( 'CustomerManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=11, ) # You should authenticate for Bing Ads production services with a Microsoft Account, # instead of providing the Bing Ads username and password set. # Authentication with a Microsoft Account is currently not supported in Sandbox. authenticate_with_oauth(authorization_data) # Uncomment to run with Bing Ads legacy UserName and Password credentials. # For example you would use this method to authenticate in sandbox. #authenticate_with_username(authorization_data) # Set to an empty user identifier to get the current authenticated Bing Ads user, # and then search for all accounts the user may access. user = customer_service.GetUser(None).User accounts = search_accounts_by_user_id(customer_service, user.Id) # For this example we'll use the first account. authorization_data.account_id = accounts['Account'][11].Id authorization_data.customer_id = accounts['Account'][11].ParentCustomerId
def __init__(self, authorization_data, poll_interval_in_milliseconds=5000, environment='production', working_directory=None, **suds_options): """ Initialize a new instance of this class. :param authorization_data: Represents a user who intends to access the corresponding customer and account. :type authorization_data: AuthorizationData :param environment: (optional) Represents which API environment to use, default is `production`, you can also pass `sandbox` in :type environment: str :param poll_interval_in_milliseconds: (optional) The time interval in milliseconds between two status polling attempts. The default value is 15000 milliseconds. :type poll_interval_in_milliseconds: int :param working_directory: (optional) Directory for storing temporary files needed for some operations (for example :func:`upload_entities` creates a temporary upload file). :param suds_options: The suds options need to pass to suds client """ self._environment = environment self._service_client = ServiceClient('BulkService', 12, authorization_data, environment, **suds_options) self._authorization_data = authorization_data self._poll_interval_in_milliseconds = poll_interval_in_milliseconds self._working_directory = os.path.join(tempfile.gettempdir(), WORKING_NAME) if working_directory is not None: self._working_directory = working_directory # make sure the working directory exists or create it. if not os.path.exists(self._working_directory): os.makedirs(self._working_directory) self._suds_options = suds_options
def __init__(self, request_id, authorization_data, poll_interval_in_milliseconds=15000, environment='production', **suds_options): self._request_id = request_id self._service_client = ServiceClient('BulkService', authorization_data, environment, version='v11', **suds_options) self._authorization_data = authorization_data self._poll_interval_in_milliseconds = poll_interval_in_milliseconds self._final_status = None
def get_service( self, service_name: str, account_id: Optional[str] = None, ) -> ServiceClient: return ServiceClient( service=service_name, version=self.api_version, authorization_data=self._get_auth_data(account_id), environment=self.environment, )
def authenticate(self, authorization_data): customer_service = ServiceClient( service='CustomerManagementService', version=13, authorization_data=authorization_data, environment=self.ENVIRONMENT, ) # You should authenticate for Bing Ads API service operations with a Microsoft Account. self.authenticate_with_oauth(authorization_data) # Set to an empty user identifier to get the current authenticated Microsoft Advertising user, # and then search for all accounts the user can access. user = get_user_response = customer_service.GetUser(UserId=None).User accounts = self.search_accounts_by_user_id(customer_service, user.Id) # Custom Added Code account_ids = [{k.Id: k.Name} for k in accounts['AdvertiserAccount']] print(account_ids) # For this example we'll use the first account. # authorization_data.account_id = accounts['AdvertiserAccount'][0].Id # authorization_data.customer_id = accounts['AdvertiserAccount'][0].ParentCustomerId return [k.Id for k in accounts['AdvertiserAccount']]
# The report file extension type. REPORT_FILE_FORMAT = 'Csv' # The maximum amount of time (in milliseconds) that you want to wait for the report download. TIMEOUT_IN_MILLISECONDS = 3600000 authorization_data = AuthorizationData( account_id=None, customer_id=None, developer_token=DEVELOPER_TOKEN, authentication=None, ) customer_service = ServiceClient( 'CustomerManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=9, ) reporting_service_manager = ReportingServiceManager( authorization_data=authorization_data, poll_interval_in_milliseconds=5000, environment=ENVIRONMENT, ) # In addition to ReportingServiceManager, you will need a reporting ServiceClient # to build the ReportRequest. reporting_service = ServiceClient( 'ReportingService', authorization_data=authorization_data,
# Poll for downloads at reasonable intervals. You know your data better than anyone. # If you download an account that is well less than one million keywords, consider polling # at 15 to 20 second intervals. If the account contains about one million keywords, consider polling # at one minute intervals after waiting five minutes. For accounts with about four million keywords, # consider polling at one minute intervals after waiting 10 minutes. bulk_service=BulkServiceManager( authorization_data=authorization_data, poll_interval_in_milliseconds=5000, environment=ENVIRONMENT, ) campaign_service=ServiceClient( service='CampaignManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=10, ) customer_service=ServiceClient( 'CustomerManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=9, ) def authenticate_with_username(): ''' Sets the authentication property of the global AuthorizationData instance with PasswordAuthentication. ''' global authorization_data
LANGUAGE_LOCALE = "en" # The only supported file format version is 1.0. VERSION = "1.0" authorization_data = AuthorizationData( account_id=None, customer_id=None, developer_token=DEVELOPER_TOKEN, authentication=None, ) campaign_service = ServiceClient( service='CampaignManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=10, ) customer_service = ServiceClient( 'CustomerManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=9, ) def authenticate_with_username(): ''' Sets the authentication property of the global AuthorizationData instance with PasswordAuthentication. '''
ENVIRONMENT = 'production' # If you are using OAuth in production, CLIENT_ID is required and CLIENT_STATE is recommended. CLIENT_ID = 'ClientIdGoesHere' CLIENT_STATE = 'ClientStateGoesHere' authorization_data = AuthorizationData( account_id=None, customer_id=None, developer_token=DEVELOPER_TOKEN, authentication=None, ) campaign_service = ServiceClient( service='CampaignManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=10, ) customer_service = ServiceClient( 'CustomerManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=9, ) def authenticate_with_username(): ''' Sets the authentication property of the global AuthorizationData instance with PasswordAuthentication. '''
ALL_AD_TYPES = { 'AdType': ['AppInstall', 'DynamicSearch', 'ExpandedText', 'Product', 'Text'] } authorization_data = AuthorizationData( account_id=None, customer_id=None, developer_token=DEVELOPER_TOKEN, authentication=None, ) campaign_service = ServiceClient( service='CampaignManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=10, ) customer_service = ServiceClient( 'CustomerManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=9, ) def authenticate_with_username(): ''' Sets the authentication property of the global AuthorizationData instance with PasswordAuthentication. '''
ENVIRONMENT = 'production' # If you are using OAuth in production, CLIENT_ID is required and CLIENT_STATE is recommended. CLIENT_ID = 'ClientIdGoesHere' CLIENT_STATE = 'ClientStateGoesHere' authorization_data = AuthorizationData( account_id=None, customer_id=None, developer_token=DEVELOPER_TOKEN, authentication=None, ) campaign_service = ServiceClient( service='CampaignManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=10, ) customer_service = ServiceClient( 'CustomerManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=9, ) def authenticate_with_username(): ''' Sets the authentication property of the global AuthorizationData instance with PasswordAuthentication. '''
ENVIRONMENT = 'production' # If you are using OAuth in production, CLIENT_ID is required and CLIENT_STATE is recommended. CLIENT_ID = 'ClientIdGoesHere' CLIENT_STATE = 'ClientStateGoesHere' authorization_data = AuthorizationData( account_id=None, customer_id=None, developer_token=DEVELOPER_TOKEN, authentication=None, ) campaign_service = ServiceClient( service='CampaignManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=10, ) customer_service = ServiceClient( 'CustomerManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=9, ) def authenticate_with_username(): ''' Sets the authentication property of the global AuthorizationData instance with PasswordAuthentication. '''
DEVELOPER_TOKEN = 'DeveloperTokenGoesHere' ENVIRONMENT = 'production' # If you are using OAuth in production, CLIENT_ID is required and CLIENT_STATE is recommended. CLIENT_ID = 'ClientIdGoesHere' CLIENT_STATE = 'ClientStateGoesHere' authorization_data = AuthorizationData( account_id=None, customer_id=None, developer_token=DEVELOPER_TOKEN, authentication=None, ) adinsight_service = ServiceClient(service='AdInsightService', authorization_data=authorization_data, environment=ENVIRONMENT, version=10) campaign_service = ServiceClient( service='CampaignManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=10, ) customer_service = ServiceClient( 'CustomerManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=9, )
ENVIRONMENT = 'production' # If you are using OAuth in production, CLIENT_ID is required and CLIENT_STATE is recommended. CLIENT_ID = 'ClientIdGoesHere' CLIENT_STATE = 'ClientStateGoesHere' authorization_data = AuthorizationData( account_id=None, customer_id=None, developer_token=DEVELOPER_TOKEN, authentication=None, ) campaign_service = ServiceClient( service='CampaignManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=10, ) customer_service = ServiceClient( 'CustomerManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=9, ) def authenticate_with_username(): ''' Sets the authentication property of the global AuthorizationData instance with PasswordAuthentication. '''
ENVIRONMENT = 'production' # If you are using OAuth in production, CLIENT_ID is required and CLIENT_STATE is recommended. CLIENT_ID = 'ClientIdGoesHere' CLIENT_STATE = 'ClientStateGoesHere' authorization_data = AuthorizationData( account_id=None, customer_id=None, developer_token=DEVELOPER_TOKEN, authentication=None, ) campaign_service = ServiceClient( service='CampaignManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=10, ) customer_service = ServiceClient( 'CustomerManagementService', authorization_data=authorization_data, environment=ENVIRONMENT, version=9, ) def authenticate_with_username(): ''' Sets the authentication property of the global AuthorizationData instance with PasswordAuthentication. '''