Thanks Eric, works great !!. -Jeya
On Jan 20, 9:33 am, AdWords API Advisor <[email protected]> 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... > > 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 > > On Jan 18, 3:52 pm, JS <[email protected]> wrote: > > > > > Hi , > > I am new to PHP and Adwords API. Can someone please post an example > > (using PHP) on how to get the CampaignStats given a Campaign ID .I can > > get it for all campaigns, but not sure how to use the Selector for > > Active Campaigns. Please see code snippet below:- > > > $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
-- You received this message because you are subscribed to the Google Groups "AdWords API Forum" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/adwords-api?hl=en.
