def testAddCampaigns(self):
   """Test whether we can add two campaigns."""
   operations = [
       {
           'operator': 'ADD',
           'operand': {
               'name': 'Campaign #%s' % Utils.GetUniqueName(),
               'status': 'PAUSED',
               'biddingStrategy': {
                   'type': 'ManualCPC'
               },
               'endDate': '20110101',
               'budget': {
                   'period': 'DAILY',
                   'amount': {
                       'microAmount': '1000000'
                   },
                   'deliveryMethod': 'STANDARD'
               }
           }
       },
       {
           'operator': 'ADD',
           'operand': {
               'name': 'Campaign #%s' % Utils.GetUniqueName(),
               'status': 'PAUSED',
               'biddingStrategy': {
                   'type': 'ManualCPC'
               },
               'endDate': '20110101',
               'budget': {
                   'period': 'DAILY',
                   'amount': {
                       'microAmount': '2000000'
                   },
                   'deliveryMethod': 'STANDARD'
               }
           }
       }
   ]
   campaigns = self.__class__.service.Mutate(operations)
   self.__class__.campaign1 = campaigns[0]['value'][0]
   self.__class__.campaign2 = campaigns[0]['value'][1]
   self.assert_(isinstance(campaigns, tuple))
   self.assertEqual(
       Utils.GetMethodCost(self.__class__.VERSION,
                           self.__class__.service.__class__.__name__,
                           'mutate.ADD',
                           client.GetLastOperations(),
                           True),
       client.GetLastUnits())
Beispiel #2
0
    def setUp(self):
        """Prepare unittest."""
        print self.id()
        if not self.__class__.service:
            self.__class__.service = client.GetAdGroupAdService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)

        if self.__class__.campaign_id is '0' or self.__class__.ad_group_id is '0':
            campaign_service = client.GetCampaignService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            operations = [{
                'operator': 'ADD',
                'operand': {
                    'name': 'Campaign #%s' % Utils.GetUniqueName(),
                    'status': 'PAUSED',
                    'biddingStrategy': {
                        'type': 'ManualCPC'
                    },
                    'budget': {
                        'period': 'DAILY',
                        'amount': {
                            'microAmount': '1000000'
                        },
                        'deliveryMethod': 'STANDARD'
                    }
                }
            }]
            self.__class__.campaign_id = \
                campaign_service.Mutate(operations)[0]['value'][0]['id']
            ad_group_service = client.GetAdGroupService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            operations = [{
                'operator': 'ADD',
                'operand': {
                    'campaignId': self.__class__.campaign_id,
                    'name': 'AdGroup #%s' % Utils.GetUniqueName(),
                    'status': 'ENABLED',
                    'bids': {
                        'type': 'ManualCPCAdGroupBids',
                        'keywordMaxCpc': {
                            'amount': {
                                'microAmount': '1000000'
                            }
                        }
                    }
                }
            }]
            self.__class__.ad_group_id = ad_group_service.Mutate(
                operations)[0]['value'][0]['id']
Beispiel #3
0
 def testAddAdGroupKeyword(self):
     """Test whether we can add an ad group for keywords."""
     operations = [{
         'operator': 'ADD',
         'operand': {
             'campaignId': self.__class__.cpc_campaign_id,
             'name': 'AdGroup #%s' % Utils.GetUniqueName(),
             'status': 'ENABLED',
             'bids': {
                 'type': 'ManualCPCAdGroupBids',
                 'keywordMaxCpc': {
                     'amount': {
                         'microAmount': '1000000'
                     }
                 }
             }
         }
     }]
     ad_groups = self.__class__.service.Mutate(operations)
     self.__class__.ad_group = ad_groups[0]['value'][0]
     self.assert_(isinstance(ad_groups, tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'mutate.ADD', client.GetLastOperations(),
                             True), client.GetLastUnits())
Beispiel #4
0
    def setUp(self):
        """Prepare unittest."""
        print self.id()
        if not self.__class__.service:
            self.__class__.service = client.GetAdGroupService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)

        if (self.__class__.cpc_campaign_id is '0'):
            campaign_service = client.GetCampaignService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            operations = [{
                'operator': 'ADD',
                'operand': {
                    'name': 'Campaign #%s' % Utils.GetUniqueName(),
                    'status': 'PAUSED',
                    'biddingStrategy': {
                        'type': 'ManualCPC'
                    },
                    'endDate': '20110101',
                    'budget': {
                        'period': 'DAILY',
                        'amount': {
                            'microAmount': '2000000'
                        },
                        'deliveryMethod': 'STANDARD'
                    }
                }
            }]
            self.__class__.cpc_campaign_id = \
                campaign_service.Mutate(operations)[0]['value'][0]['id']
 def testAddKeywordPerformanceReport(self):
     """Test whether we can add a keywords performance report."""
     operations = [{
         'operator': 'ADD',
         'operand': {
             'type':
             'ReportDefinition',
             'reportName':
             ('Keywords performance report #%s' % Utils.GetUniqueName()),
             'dateRangeType':
             'CUSTOM_DATE',
             'reportType':
             'KEYWORDS_PERFORMANCE_REPORT',
             'downloadFormat':
             'XML',
             'selector': {
                 'fields': [
                     'AdGroupId', 'Id', 'KeywordText', 'KeywordMatchType',
                     'Impressions', 'Clicks', 'Cost'
                 ],
                 'predicates': [{
                     'field': 'AdGroupId',
                     'operator': 'EQUALS',
                     'values': [self.__class__.ad_group_id]
                 }],
                 'dateRange': {
                     'min': '20100101',
                     'max': '20100131'
                 }
             }
         }
     }]
     report_definition = self.__class__.service.Mutate(operations)
     self.__class__.report_definition_id = report_definition[0]['id']
     self.assert_(isinstance(report_definition, tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'mutate.ADD', client.GetLastOperations(),
                             True), client.GetLastUnits())
  def setUp(self):
    """Prepare unittest."""
    print self.id()
    if not self.__class__.service:
      self.__class__.service = client.GetCampaignAdExtensionService(
          self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)

    if self.__class__.campaign_id is '0':
      campaign_service = client.GetCampaignService(
          self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
      operations = [{
          'operator': 'ADD',
          'operand': {
              'name': 'Campaign #%s' % Utils.GetUniqueName(),
              'status': 'PAUSED',
              'biddingStrategy': {
                  'type': 'ManualCPC'
              },
              'budget': {
                  'period': 'DAILY',
                  'amount': {
                      'microAmount': '1000000'
                  },
                  'deliveryMethod': 'STANDARD'
              }
          }
      }]
      self.__class__.campaign_id = \
          campaign_service.Mutate(operations)[0]['value'][0]['id']

    if not self.__class__.geo_location:
      geo_location_service = client.GetGeoLocationService(
          self.__class__.SERVER, self.__class__.VERSION)
      selector = {
        'addresses': [self.__class__.address]
      }
      self.__class__.geo_location = \
          geo_location_service.Get(selector)[0]
Beispiel #7
0
        'ad': {
            'type': 'ImageAd',
            'image': {
                'dimensions': [{
                    'key': 'FULL',
                    'value': {
                        'width': '300',
                        'height': '250'
                    }
                }],
                'name':
                'image.jpg',
                'data':
                image_data
            },
            'name': 'Cruise to mars image ad #%s' % Utils.GetUniqueName(),
            'url': 'http://www.example.com',
            'displayUrl': 'www.example.com'
        }
    }
}, {
    'operator': 'ADD',
    'operand': {
        'type': 'AdGroupAd',
        'adGroupId': ad_group_id,
        'ad': {
            'type':
            'TemplateAd',
            'templateId':
            '9',
            'templateElements': [{
Beispiel #8
0
from aw_api.Client import Client
from aw_api.Errors import RequestError

# Initialize client object.
client = Client(path='../..')

# Initialize appropriate service with validate only flag enabled.
client.validate_only = True
campaign_service = client.GetCampaignService(
    'https://adwords-sandbox.google.com', 'v201003')

# Construct operations for adding campaign object and attempt to add campaign.
operations = [{
    'operator': 'ADD',
    'operand': {
        'name': 'Campaign #%s' % Utils.GetUniqueName(),
        'status': 'PAUSED',
        'biddingStrategy': 'ManualCPC',
        'budget': {
            'period': 'DAILY',
            'amount': {
                'microAmount': '50000000'
            },
            'deliveryMethod': 'STANDARD'
        }
    }
}]
campaigns = campaign_service.Mutate(operations)[0]

# Display results.
if campaigns:
    def setUp(self):
        """Prepare unittest."""
        print self.id()
        if not self.__class__.service:
            self.__class__.service = client.GetAdExtensionOverrideService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)

        if self.__class__.campaign_id is '0':
            campaign_service = client.GetCampaignService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            operations = [{
                'operator': 'ADD',
                'operand': {
                    'name': 'Campaign #%s' % Utils.GetUniqueName(),
                    'status': 'PAUSED',
                    'biddingStrategy': {
                        'type': 'ManualCPC'
                    },
                    'budget': {
                        'period': 'DAILY',
                        'amount': {
                            'microAmount': '1000000'
                        },
                        'deliveryMethod': 'STANDARD'
                    }
                }
            }]
            self.__class__.campaign_id = \
                campaign_service.Mutate(operations)[0]['value'][0]['id']
            ad_group_service = client.GetAdGroupService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            operations = [{
                'operator': 'ADD',
                'operand': {
                    'campaignId': self.__class__.campaign_id,
                    'name': 'AdGroup #%s' % Utils.GetUniqueName(),
                    'status': 'ENABLED',
                    'bids': {
                        'type': 'ManualCPCAdGroupBids',
                        'keywordMaxCpc': {
                            'amount': {
                                'microAmount': '1000000'
                            }
                        }
                    }
                }
            }]
            ad_group_id = ad_group_service.Mutate(
                operations)[0]['value'][0]['id']
            ad_service = client.GetAdGroupAdService(self.__class__.SERVER,
                                                    self.__class__.VERSION,
                                                    HTTP_PROXY)
            operations = [{
                'operator': 'ADD',
                'operand': {
                    'type': 'AdGroupAd',
                    'adGroupId': ad_group_id,
                    'ad': {
                        'type': 'TextAd',
                        'url': 'http://www.example.com',
                        'displayUrl': 'example.com',
                        'status': 'ENABLED',
                        'description1': 'Visit the Red Planet in style.',
                        'description2': 'Low-gravity fun for everyone!',
                        'headline': 'Luxury Cruise to Mars'
                    }
                }
            }]
            self.__class__.ad_id = \
                ad_service.Mutate(operations)[0]['value'][0]['ad']['id']

        if not self.__class__.geo_location:
            geo_location_service = client.GetGeoLocationService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            selector = {'addresses': [self.__class__.address]}
            self.__class__.geo_location = \
                geo_location_service.Get(selector)[0]

        if self.__class__.ad_extension_id is '0':
            campaign_ad_extension_service = client.GetCampaignAdExtensionService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            operations = [{
                'operator': 'ADD',
                'operand': {
                    'type': 'CampaignAdExtension',
                    'campaignId': self.__class__.campaign_id,
                    'adExtension': {
                        'type':
                        'LocationExtension',
                        'address':
                        self.__class__.geo_location['address'],
                        'geoPoint':
                        self.__class__.geo_location['geoPoint'],
                        'encodedLocation':
                        self.__class__.geo_location['encodedLocation'],
                        'source':
                        'ADWORDS_FRONTEND'
                    }
                }
            }]
            self.__class__.ad_extension_id = \
                campaign_ad_extension_service.Mutate(
                    operations)[0]['value'][0]['adExtension']['id']
# Import appropriate classes from the client library.
from aw_api import Utils
from aw_api.Client import Client

# Initialize client object.
client = Client(path='../..')

# Initialize appropriate service.
campaign_service = client.GetCampaignService(
    'https://adwords-sandbox.google.com', 'v201003')

# Construct operations and add campaign.
operations = [{
    'operator': 'ADD',
    'operand': {
        'name': 'Interplanetary Cruise #%s' % Utils.GetUniqueName(),
        'status': 'PAUSED',
        'biddingStrategy': {
            'type': 'ManualCPC'
        },
        'endDate': '20110101',
        'budget': {
            'period': 'DAILY',
            'amount': {
                'microAmount': '50000000'
            },
            'deliveryMethod': 'STANDARD'
        }
    }
}]
campaigns = campaign_service.Mutate(operations)[0]
# Initialize appropriate service.
report_definition_service = client.GetReportDefinitionService(
    'https://adwords-sandbox.google.com', 'v201003')

ad_group_id = 'INSERT_AD_GROUP_ID_HERE'
start_date = 'INSERT_START_DATE_HERE'
end_date = 'INSERT_END_DATE_HERE'

# Construct operations and create report definition.
operations = [{
    'operator': 'ADD',
    'operand': {
        'type': 'ReportDefinition',
        'reportName':
        ('Keywords performance report #%s' % Utils.GetUniqueName()),
        'dateRangeType': 'CUSTOM_DATE',
        'reportType': 'KEYWORDS_PERFORMANCE_REPORT',
        'downloadFormat': 'XML',
        'selector': {
            'fields': [
                'AdGroupId', 'Id', 'KeywordText', 'KeywordMatchType',
                'Impressions', 'Clicks', 'Cost'
            ],
            'predicates': [{
                'field': 'AdGroupId',
                'operator': 'EQUALS',
                'values': [ad_group_id]
            }],
            'dateRange': {
                'min': start_date,
Beispiel #12
0
    def setUp(self):
        """Prepare unittest."""
        print self.id()
        if not self.__class__.service:
            self.__class__.service = client.GetAdParamService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)

        if (self.__class__.ad_group_id is '0'
                or self.__class__.text_ad_id is '0'
                or self.__class__.criterion_id is '0'):
            campaign_service = client.GetCampaignService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            operations = [{
                'operator': 'ADD',
                'operand': {
                    'name': 'Campaign #%s' % Utils.GetUniqueName(),
                    'status': 'PAUSED',
                    'biddingStrategy': {
                        'type': 'ManualCPC'
                    },
                    'endDate': '20110101',
                    'budget': {
                        'period': 'DAILY',
                        'amount': {
                            'microAmount': '2000000'
                        },
                        'deliveryMethod': 'STANDARD'
                    }
                }
            }]
            campaign_id = campaign_service.Mutate(
                operations)[0]['value'][0]['id']
            ad_group_service = client.GetAdGroupService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            operations = [{
                'operator': 'ADD',
                'operand': {
                    'campaignId': campaign_id,
                    'name': 'AdGroup #%s' % Utils.GetUniqueName(),
                    'status': 'ENABLED',
                    'bids': {
                        'type': 'ManualCPCAdGroupBids',
                        'keywordMaxCpc': {
                            'amount': {
                                'microAmount': '1000000'
                            }
                        }
                    }
                }
            }]
            self.__class__.ad_group_id = \
                ad_group_service.Mutate(operations)[0]['value'][0]['id']
            ad_group_ad_service = client.GetAdGroupAdService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            operations = [{
                'operator': 'ADD',
                'operand': {
                    'type': 'AdGroupAd',
                    'adGroupId': self.__class__.ad_group_id,
                    'ad': {
                        'type': 'TextAd',
                        'url': 'http://www.example.com',
                        'displayUrl': 'example.com',
                        'status': 'ENABLED',
                        'description1': 'Good deals, only {param2:} left',
                        'description2': 'Low prices under {param1:}!',
                        'headline': 'MacBook Pro Sale'
                    }
                }
            }]
            self.__class__.text_ad_id = \
                ad_group_ad_service.Mutate(operations)[0]['value'][0]['ad']['id']
            ad_group_criterion_service = \
                client.GetAdGroupCriterionService(
                    self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            operations = [{
                'operator': 'ADD',
                'operand': {
                    'type': 'BiddableAdGroupCriterion',
                    'adGroupId': self.__class__.ad_group_id,
                    'criterion': {
                        'type': 'Keyword',
                        'matchType': 'BROAD',
                        'text': 'macbook pro'
                    }
                }
            }]
            self.__class__.criterion_id = ad_group_criterion_service.Mutate(
                operations)[0]['value'][0]['criterion']['id']
# Initialize client object.
client = Client(path='../..')

# Initialize appropriate service.
ad_group_service = client.GetAdGroupService(
    'https://adwords-sandbox.google.com', 'v200909')

campaign_id = 'INSERT_CAMPAIGN_ID_HERE'

# Construct operations and add an ad group.
operations = [{
    'operator': 'ADD',
    'operand': {
        'campaignId': campaign_id,
        'name': 'Earth to Mars Cruises #%s' % Utils.GetUniqueName(),
        'status': 'ENABLED',
        'bids': {
            'type': 'ManualCPCAdGroupBids',
            'keywordMaxCpc': {
                'amount': {
                    'microAmount': '10000000'
                }
            }
        }
    }
}]
ad_groups = ad_group_service.Mutate(operations)[0]

# Display results.
for ad_group in ad_groups['value']: