Esempio n. 1
0
try {
    // Get DfpUser from credentials in "../auth.ini"
    // relative to the DfpUser.php file's directory.
    $user = new DfpUser();
    // Log SOAP XML request and response.
    $user->LogDefaults();
    // Get the PublisherQueryLanguageService.
    $pqlService = $user->GetService('PublisherQueryLanguageService', 'v201411');
    // Create statement to select all line items.
    $lineItemStatementBuilder = new StatementBuilder();
    $lineItemStatementBuilder->Select('Id, Name, Status')->From('Line_Item')->OrderBy('Id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    // Create statement to select all ad units.
    $adUnitStatementBuilder = new StatementBuilder();
    $adUnitStatementBuilder->Select('Id, Name')->From('Ad_Unit')->OrderBy('Id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    $lineItemFilePath = fetchMatchTable($lineItemStatementBuilder, $pqlService, "Line-Item-Matchtable");
    $adUnitFilePath = fetchMatchTable($adUnitStatementBuilder, $pqlService, "Ad-Unit-Matchtable");
    printf("Line items saved to %s\n", $lineItemFilePath);
    printf("Ad units saved to %s\n", $adUnitFilePath);
} catch (OAuth2Exception $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (ValidationException $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (Exception $e) {
    printf("%s\n", $e->getMessage());
}
/**
 * Fetches a match table from a PQL statement and writes it to a file.
 */
function fetchMatchTable($statementBuilder, $pqlService, $fileName)
{
    $resultSet = null;
require_once 'Google/Api/Ads/Dfp/Util/Pql.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
try {
    // Get DfpUser from credentials in "../auth.ini"
    // relative to the DfpUser.php file's directory.
    $user = new DfpUser();
    // Log SOAP XML request and response.
    $user->LogDefaults();
    // Get the PublisherQueryLanguageService.
    $pqlService = $user->GetService('PublisherQueryLanguageService', 'v201405');
    // Statement parts to help build a statement to select all line items.
    $lineItemPqlTemplate = 'SELECT Id, Name, Status FROM Line_Item ORDER BY Id ' . 'ASC LIMIT %d OFFSET %d';
    // Statement parts to help build a statement to select all ad units.
    $adUnitPqlTemplate = 'SELECT Id, Name FROM Ad_Unit ORDER BY Id ASC LIMIT ' . '%d OFFSET %d';
    $lineItemFilePath = fetchMatchTable($lineItemPqlTemplate, $pqlService, "Line-Item-Matchtable");
    $adUnitFilePath = fetchMatchTable($adUnitPqlTemplate, $pqlService, "Ad-Unit-Matchtable");
    printf("Line items saved to %s\n", $lineItemFilePath);
    printf("Ad units saved to %s\n", $adUnitFilePath);
} catch (OAuth2Exception $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (ValidationException $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (Exception $e) {
    printf("%s\n", $e->getMessage());
}
/**
 * Fetches a match table from a PQL statement and writes it to a file.
 */
function fetchMatchTable($pqlTemplate, $pqlService, $fileName)
{
    $SUGGESTED_PAGE_LIMIT = 500;