Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page token has expired #366

Closed
fresh7849 opened this issue Jun 17, 2020 · 1 comment
Closed

Page token has expired #366

fresh7849 opened this issue Jun 17, 2020 · 1 comment

Comments

@fresh7849
Copy link

Description:
Get a account placemet report(there's a lot of data ). Every time the script runs two or three hours, an exception is thrown.

The script code:

protected function initClient()
{
    try {
        $oAuth2Credetial = (new OAuth2TokenBuilder())->fromFile($this->account['certification_file'])
            ->build();

        $this->client = (new GoogleAdsClientBuilder())->fromFile($this->account['certification_file'])
            ->withOAuth2Credential($oAuth2Credetial)
            ->withLogger(app('log'))
            ->build();
    } catch (InvalidArgumentException $th) {
        info(__METHOD__ . ',info:' . $th->getMessage());
    }
    return true;
}

protected function getAdsService()
{
    if ($this->client instanceof GoogleAdsClient) {
        return $this->client->getGoogleAdsServiceClient();
    }
    info(__METHOD__ . ' empty service, ' . $this->baseLogStr);
    throw new AdvertiseException("Empty google ads service", AdvertiseException::INIT_API_ERROR);
}

public function placementReport()
{
    $service = $this->getAdsService();
    $query = "query language... ";
    try {
        $iterator = $service->search($this->account['account_id'], $query, ['pageSize' => 2500]);
        foreach ($iterator->iterateAllElements() as $googleAdsRow) {
            // deal something ..., spended a little time(about 2 seconds).
        }
    } catch (ApiException $th) {
        info(__METHOD__ . ', info:' . $th->getMessage() . ', ' . $this->baseLogStr);
    }
}

Exception descripiton:
image

image

@fiboknacky
Copy link
Member

Please decrease the number of your selected fields and date range and try again.
It's likely that your page token will be expired before you can get all data, if you're trying to fetch too much data.

For further questions regarding the API usage, in general, could you post in this forum instead?
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants