i used the aw_api_php_lib_2.5.1.

how i can download a cross client report?

A single report is not a Problem, but crossclient....

My Code is:
[code]
    public function download() {
        require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
        require_once 'Google/Api/Ads/AdWords/Util/ReportUtils.php';
        require_once 
'Google/Api/Ads/AdWords/v201101/cm/ReportDefinitionService.php';
        require_once 
'Google/Api/Ads/AdWords/v201101/cm/CampaignService.php';
        require_once 
'Google/Api/Ads/AdWords/Util/ReportDownloadException.php';

        //Nur ändern wenn sich mal wieder die Feldbezeichnungen bei Google 
ändern//

        $AD_PERFORMANCE_REPORT = array(    
                                              'Date',                     
#date                     AD_PERFORMANCE_REPORT
                                              'AccountDescriptiveName',    
#account                 AD_PERFORMANCE_REPORT
                                              'ExternalCustomerId',        
#customerid             AD_PERFORMANCE_REPORT
                                              'AdGroupId',                
#AdGroupId                AD_PERFORMANCE_REPORT
                                              'AdGroupName',                
#AdGroupName            AD_PERFORMANCE_REPORT
                                              'Headline',                    
#Headline                AD_PERFORMANCE_REPORT
                                              'Description1',                
#Description2            AD_PERFORMANCE_REPORT
                                              'Description2',                
#Description2            AD_PERFORMANCE_REPORT
                                              'DisplayUrl',                
#DisplayUrl                AD_PERFORMANCE_REPORT
                                              'CreativeApprovalStatus',    
#CreativeApprovalStatus    AD_PERFORMANCE_REPORT
                                                'AdGroupStatus',            
#AdGroupStatus            AD_PERFORMANCE_REPORT
                                                'Url',                    
    #Url                    AD_PERFORMANCE_REPORT
                                                'CampaignStatus',            
#CampaignStatus            AD_PERFORMANCE_REPORT
                                                'Impressions',            
    #Impressions            AD_PERFORMANCE_REPORT
                                                'Clicks',                    
#Clicks                    AD_PERFORMANCE_REPORT
                                                'Cost',                    
    #Cost                     AD_PERFORMANCE_REPORT
                                                'AveragePosition',        
    #AveragePosition          AD_PERFORMANCE_REPORT
                                                'Conversions',            
    #Conversions            AD_PERFORMANCE_REPORT
                                                'ConversionValue',        
    #ConversionValue           AD_PERFORMANCE_REPORT
                                              'AccountCurrencyCode'        
#AccountCurrencyCode    AD_PERFORMANCE_REPORT
                                      );        
        $CAMPAIGN_PERFORMANCE_REPORT = array(    
                                              'Amount'                    
#Budget                 CAMPAIGN_PERFORMANCE_REPORT
                                      );                
                                      
        $CREATIVE_CONVERSION_REPORT = array(    
                                              'CreativeId'                
#CreativeId                CREATIVE_CONVERSION_REPORT
                                      );        
                                      
        //Nur ändern wenn sich mal wieder die Feldbezeichnungen bei Google 
ändern//
        
        //Da wir nach dem Umstieg von API v13 auf v201101 nicht mehr mit 
einem Bericht auskommen, müssen wir 3 Berichte ziehen                       
                
        $aReportDefinitionFields             = 
array($AD_PERFORMANCE_REPORT,$CAMPAIGN_PERFORMANCE_REPORT,$CREATIVE_CONVERSION_REPORT);
        $aReportDefinitionFieldsDescription = 
array('AD_PERFORMANCE_REPORT','CAMPAIGN_PERFORMANCE_REPORT','CREATIVE_CONVERSION_REPORT');
                                      
        $time = time();
        $datum = date("dmYHis",$time);                         
        $dirs = $this->conf->parser->directories;
        $newacc = $this->getAccount();
           
        #############

        $timer = new Backend_Model_Timer();
        echo"Timer wurde gestartet\n";
        
        

        
                //nötige Daten aus der application.ini ziehen
                $conf = new Zend_Config_Ini(APPLICATION_PATH . 
'/configs/application.ini', "GOOGLEAPI");
        
                //AdwordsUser erstellen
                  $ouser         =    new AdWordsUser();
                  //Autentifizierungstoken erstellen
                  $authToken     =     new AuthToken($ouser->GetEmail(), 
$ouser->GetPassword(), 'adwords', 'IMIQ', 'GOOGLE');
                  
                $ouser->SetClientId(my MCC ID);
                  $ouser->SetAuthToken($authToken->GetAuthToken());    
//Setzten unserer Authentifizierung
                $ouser->LogDefaults();                                
//Logmechanismus
                
                //Welche API nutzen wir?
                $reportDefinitionService = 
$ouser->GetReportDefinitionService('v201101');
                
                //für jeden Reporttyp einen Download starten
                foreach($aReportDefinitionFields as $key => $value){
                    //Namen für die Berichte erstellen
                    $sfileName = $dirs->reports . '/' . 
$this->getUniqueFilename($time,$aReportDefinitionFieldsDescription[$key]);
                    
                    //Den Selector erstellen
                    $selector = $this->CreateSelector($value);
                    $selector->dateRange = new 
DateRange(str_replace("-","",$this->startdate), 
str_replace("-","",$this->enddate));
                    
                    //Report Definition erstellen
                    $reportDefinition = new ReportDefinition();
                      $reportDefinition->reportName = 
$aReportDefinitionFieldsDescription[$key].' ## ' . $datum;
                      $reportDefinition->dateRangeType = 'CUSTOM_DATE';
                      $reportDefinition->reportType = 
$aReportDefinitionFieldsDescription[$key];
                      $reportDefinition->downloadFormat = 'GZIPPED_CSV';
                      $reportDefinition->selector = $selector;
                      $reportDefinition->crossClient = true;

                      
                      $clientSelector = new ClientSelector();
                      $clientSelector->login = "EMAILFROMCUSTOMER";

                      $reportDefinition->clientSelectors = $clientSelector;

                      
                  
                      
                      // Create operations
                      $operation = new ReportDefinitionOperation();
                      $operation->operand = $reportDefinition;
                      $operation->operator = 'ADD';
                 
                      $operations = array($operation);
                      
                    //Download des Reports bei Google
                    try{
                        //Gibt es Reporte zum runterladen?
                        $result = 
$reportDefinitionService->mutate($operations);
                        
                        //für jeden Bericht der Vorhanden ist, ein Download 
durchführen
                        for($x = 0; $x < count($result); $x++ ){        
                            //pfad zum Ordner in dem die Reporte abgelegt 
werden sollen mit dem vorher erzeugtem Filename             
                            $path = $sfileName;
                            try{
                                //Download -> hier wird noch zuätzlich eine 
.lock datei erstellt und nach Beendigung entfernt
                                ReportUtils::DownloadReport($result[$x]->id, 
$path, $ouser, null, true);    
                                //zwei Sekunden warten aus 
Sicherheitsgründen
                                sleep(2);
                                echo "Vergangene Zeit seit der letzten 
Messung : ".$timer->measure_intermediate()." Sekunden \n";
                            }catch (Exception $e) {
                                
$error[$newacc->getId()][1]=$e->getMessage();
                                print_r($error);
                                  continue;
                            }
                            printf("%d - Report with definition id '%s' was 
downloaded to '%s'\n\n",
                              $y, $result[$x]->id, $sfileName);            
   
                        }
                    }catch (Exception $e) {
                        $error[$newacc->getId()][0]=$e->getMessage();
                        print_r($error);
                          continue;
                    }
                }

   
        ###########        
    }
    
    function CreateSelector($selectorFields){
                    $selector = new Selector();
                    $selector->fields = $selectorFields;
                    return $selector;
    }
[/code]

-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en

Reply via email to