$campaignService = $user->GetCampaignService('v200909');
$today = date('Y-m-d');
$start = mktime(0,0,0,date("m"),date("d")-15,date("Y"));
$end = mktime(0,0,0,date("m"),date("d")-1,date("Y"));
$start_date = date("Y-m-d", $start);
$end_date = date("Y-m-d", $end);
$campaignId = <insert_campaign_ID_here>;
// Create selector.
$selector = new CampaignSelector();
$selector->ids = array($campaignId);
$page = $campaignService->get($selector);
//Not sure how to use the selector here
$campstats = new Stats();
$campstats->start_date = $start_date;
$campstats->end_date = $end_date;
//Not sure how to use the selector here
$page = $campaignService->get($campstats);
if (isset($page->entries)) {
foreach ($page->entries as $campaign) {
echo 'Campaign ID:' . $campaign->id . ' Campaign name:' . $campaign-
>name .' Campaign startdate:"' . $campaign->startDate."<br>";
echo 'Campaign Clicks:' . $campaign->stats->clicks ."<br>"; //this
is empty at present
echo 'Campaign cost:' . $campaign->stats->cost ."<br>"; //this is
empty at present
thanks and any info is appreciated..
-Jeya
All calls made to CampaignService->get() must be made with a
CampaignSelector object:
http://code.google.com/apis/adwords/v2009/docs/reference/CampaignService.CampaignSelector.html
To retrieve stats, set the "statsSelector" field of the
CampaignSelector to a new StatsSelector object:
http://code.google.com/apis/adwords/v2009/docs/reference/CampaignService.StatsSelector.html
After the selector is configured, run the CampaignService->get() with
the CampaignSelector. For example:
// Create selector.
$selector = new CampaignSelector();
$selector->ids = array($campaignId);
// Create stats selector.
$statsSelector = new StatsSelector();
$dateRange = new DateRange();
$dateRange->min = $start_date;
$dateRange->max = $end_date;
$statsSelector->dateRange = $dateRange;
$selector->statsSelector = $statsSelector;
// Get campaigns with stats.
$page = $campaignService->get($selector);
Best,
- Eric Koleda, AdWords API Team
-Jeya
On Jan 20, 9:33 am, AdWords API Advisor <adwordsapiadvi...@google.com>
wrote:
> Hi Jeya,
>
> All calls made to CampaignService->get() must be made with a
> CampaignSelector object:
>
> http://code.google.com/apis/adwords/v2009/docs/reference/CampaignServ...
>
> To retrieve stats, set the "statsSelector" field of the
> CampaignSelector to a new StatsSelector object:
>
> http://code.google.com/apis/adwords/v2009/docs/reference/CampaignServ...
$campaign_service = SoapClientFactory::GetClient($namespace . '/
CampaignService?wsdl', 'wsdl');
$campaign_service->setHeaders($headers);
$request_xml = '<getAllAdWordsCampaigns><dummy>0</dummy></
getAllAdWordsCampaigns>';
$campaigns = $campaign_service->call('getAllAdWordsCampaigns',
$request_xml);
$campaigns = $campaigns['getAllAdWordsCampaignsReturn'];
$start_date = date("Y-m-d");//'2009-09-20';exit;
$end_date = $start_date;
//U can mention both the start date and end date according to ur
choice
$count = count($campaigns);
for ($i = 0; $i < $count; $i++) {
$campaignIds[] = $campaigns[$i]['id'];
$camp_name[] = $campaigns[$i]['name'];
$xml[] = "<getCampaignStats><campaignIds>".$campaignIds[$i]."</
campaignIds>
<startDay>".$start_date."</startDay>
<endDay>".$end_date."</endDay>
</getCampaignStats>";
$campaign_stats[$i] = $campaign_service->call('getCampaignStats',$xml
[$i]);
$campaign_stats[$i] = $campaign_stats[$i]['getCampaignStatsReturn'];
print "'".$start_date."','".$campaign_stats[$i]['impressions']."','".
$campaign_stats[$i]['clicks']."','".round($campaign_stats[$i]['cost']/
1000000,2)."','".$camp_name[$i]."'+";