Search code examples
phpgoogle-codegoogle-ads-api

Get Client Invoice via Google AdWords php API


I want to use the Google AdWords API to pull my clients invoices via php. This will make the process of billing my clients much more streamlined. How would I do this utilizing the AdWords API?


Solution

  • Unfortunately, it seems that at this current time, there is no way to retrieve invoices from a Google Adwords account. The workaround I came up with, was to access the linked Google Analytics account via the gapi (http://code.google.com/p/gapi-google-analytics-php-interface/) and generate the invoice myself. This is how to get adwords data for a specific date range:

    require("gapi.class.php");
    $gapi = new gapi("email","password");
    $ga_dimensions = '';
    $ga_metrics = array('impressions','adClicks','adCost','CTR','CPC');
    $start_date = "2011-03-01";
    $end_date = "2011-03-31";
    $gapi->requestReportData($ga_profile_id,$ga_dimensions,$ga_metrics,'','',$start_date,$end_date,1,10000);
    $ga_adwords_data = $gapi->getResults();
    foreach($ga_adwords_data as $ga_adwords_stat) {
        $ga_adwords_stats = array('impressions' => $ga_adwords_stat->getImpressions(),
                                  'clicks'      => $ga_adwords_stat->getAdClicks(),
                                  'cost'        => $ga_adwords_stat->getAdCost(),
                                  'ctr'         => $ga_adwords_stat->getCTR(),
                                  'cpc'         => $ga_adwords_stat->getCPC());
    }
    print_r($ga_adwords_stats);