Hi Jeya
This is Ipsita
I have done the exact thing u asked for.Before using the below code
you should keep your account information in 'Account_info.php' file.
require_once('soapclientfactory.php');
require_once('Account_Info.php');

$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]."'+";
}

On Jan 19, 1:52 am, 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.

Reply via email to