PAGE_SIZE on the new API

54 views
Skip to first unread message

jrodr...@norte.digital

unread,
Apr 19, 2019, 4:03:34 PM4/19/19
to AdWords API and Google Ads API Forum
Hi, I am trying to get all ad groups from my account, but the PAGE_SIZE is not working, every time i run query only get one page, i set the PAGE_SIZE = 1000 but my ad groups is over 1000 and no work the pagination, ever get this error (This page isn’t working, ERR_EMPTY_RESPONSE). I think the API should be reponse with two pages or more

googleadsapi...@google.com

unread,
Apr 19, 2019, 4:29:09 PM4/19/19
to AdWords API and Google Ads API Forum
Hello Jose,

Could you please share the client customer id from which you are pulling the AdGroups? Could you please confirm whether you are using the GetAdGroups sample available in our client libraries for example in Java GetAdGroups.java?

Regards,
Sai teja, Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

jrodr...@norte.digital

unread,
Apr 23, 2019, 10:17:32 AM4/23/19
to AdWords API and Google Ads API Forum
well i have this error ( ERR_EMPTY_RESPONSE ) when try paginate the results.
this is my entire code:

class Util
{

    public static function getIdUnformat($id)
    {
        $id_adwords=str_replace('-', '', $id);
        return $id_adwords;
    }

    public static function getGoogleAdsClient()
    {
        $cliente_id       = env('ADWORDS_CLIENT_ID');
        $cliente_secret   = env('ADWORDS_CLIENT_SECRET');
        $token            = env('ADWORDS_TOKEN');
        $developer_token  = env('ADWORDS_DEVELOPER_TOKEN');
        $id_account_mcc   = self::getIdUnformat(env('ADWORDS_ID_MCC'));

        $oAuth2Credential = (new OAuth2TokenBuilder())
      ->withClientId($cliente_id)
      ->withClientSecret($cliente_secret)
      ->withRefreshToken($token)
      ->build();

        $googleAdsClient = (new GoogleAdsClientBuilder())
        ->withDeveloperToken($developer_token)
        ->withLoginCustomerId($id_account_mcc)
        ->withOAuth2Credential($oAuth2Credential)
        ->build();
        return $googleAdsClient;
    }
}

class TestController extends Controller
{
    const PAGE_SIZE = 100;

    public function convertionAction()
    {
        $cid = "xxx-xxx-xxxx";

        $cid = Util::getIdUnformat($cid);
        $googleAdsClient = Util::getGoogleAdsClient();
        $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();

        $query = "SELECT
                 ad_group.id, ad_group.status
            FROM
                ad_group
            WHERE
                ad_group.status = 'ENABLED' ";

        $response = $googleAdsServiceClient->search($cid, $query, ['pageSize' => self::PAGE_SIZE]);

        foreach ($response->iterateAllElements() as $googleAdsRow) {
            printf(
                "ad_group.name %s, ad_group.status %s%s",
                $googleAdsRow->getAdGroup()->getId()->getValue(),
                $googleAdsRow->getAdGroup()->getStatus(),
                PHP_EOL
            );
        }

    }
}



then if i use ['pageSize' => self::PAGE_SIZE] with $response->iterateAllElements() always get this error in the browser. i  always get the same error.

but if i remove the paginate ['pageSize' => self::PAGE_SIZE]  i can paginate all results. this is the code:

class Util
{

    public static function getIdUnformat($id)
    {
        $id_adwords=str_replace('-', '', $id);
        return $id_adwords;
    }

    public static function getGoogleAdsClient()
    {
        $cliente_id       = env('ADWORDS_CLIENT_ID');
        $cliente_secret   = env('ADWORDS_CLIENT_SECRET');
        $token            = env('ADWORDS_TOKEN');
        $developer_token  = env('ADWORDS_DEVELOPER_TOKEN');
        $id_account_mcc   = self::getIdUnformat(env('ADWORDS_ID_MCC'));

        $oAuth2Credential = (new OAuth2TokenBuilder())
      ->withClientId($cliente_id)
      ->withClientSecret($cliente_secret)
      ->withRefreshToken($token)
      ->build();

        $googleAdsClient = (new GoogleAdsClientBuilder())
        ->withDeveloperToken($developer_token)
        ->withLoginCustomerId($id_account_mcc)
        ->withOAuth2Credential($oAuth2Credential)
        ->build();
        return $googleAdsClient;
    }
}

class TestController extends Controller
{
    const PAGE_SIZE = 100;

    public function convertionAction()
    {
        $cid = "xxx-xxx-xxxx";

        $cid = Util::getIdUnformat($cid);
        $googleAdsClient = Util::getGoogleAdsClient();
        $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();

        $query = "SELECT
                 ad_group.id, ad_group.status
            FROM
                ad_group
            WHERE
                ad_group.status = 'ENABLED' ";

        $response = $googleAdsServiceClient->search($cid, $query);

        foreach ($response->iterateAllElements() as $googleAdsRow) {
            printf(
                "ad_group.name %s, ad_group.status %s%s",
                $googleAdsRow->getAdGroup()->getId()->getValue(),
                $googleAdsRow->getAdGroup()->getStatus(),
                PHP_EOL
            );
        }

    }
}



however this not is the better way because always get one page.

i need your help with this.

googleadsapi...@google.com

unread,
Apr 23, 2019, 4:41:26 PM4/23/19
to AdWords API and Google Ads API Forum
Hello

Sucne you are facing the issue with the PHP client library while paginating, I recommend you to create a new issue on our issue tracker from here. Our client library owners are better equipped to answer these questions.

Regards,
Sai Teja, Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Reply all
Reply to author
Forward
0 new messages