googleapis / google-api-php-client

A PHP client library for accessing Google APIs
Apache License 2.0
9.22k stars 3.52k forks source link

Uncaught Google\Exception: (search) unknown parameter: 'pageToken' #2480

Closed FelixSche closed 12 months ago

FelixSche commented 12 months ago

Following the google documentation is a parameter you can send in to get the next page of articles. https://developers.google.com/shopping-content/reference/rest/v2.1/reports/search?apix_params=%7B%22merchantId%22%3A283548%2C%22resource%22%3A%7B%22pageToken%22%3A%22COgH%22%2C%22query%22%3A%22SELECT%20product_view.id%2C%20product_view.title%2C%20product_view.brand%2C%20product_view.price_micros%2C%20product_view.currency_code%2C%20price_competitiveness.country_code%2C%20price_competitiveness.benchmark_price_micros%2C%20%20price_competitiveness.benchmark_price_currency_code%20FROM%20PriceCompetitivenessProductView%22%7D%7D

Environment details

Steps to reproduce

  1. Request a report from the google content for shopping api
  2. grab the nextpagetoken from the response and query the content API for shopping again this time including the pageToken in the request body

Code example

$oSearchRequest = new Google_Service_ShoppingContent_SearchRequest();
  $query = 'SELECT product_view.id, product_view.title, product_view.brand, product_view.price_micros, product_view.currency_code, price_competitiveness.country_code, price_competitiveness.benchmark_price_micros,  price_competitiveness.benchmark_price_currency_code FROM PriceCompetitivenessProductView';
  $oSearchRequest->setQuery($query);

  $oShopping = new Google\Service\ShoppingContent($oGoogle);
  if ($sPageToken != '') {
    $optParams = ['pageToken' => $sPageToken];
    $oReport = $oShopping->reports->search($iMerchantID, $oSearchRequest, $optParams);
  } else {
    $oReport = $oShopping->reports->search($iMerchantID, $oSearchRequest);
  }
FelixSche commented 12 months ago

Without the pageToken the request is working just fine. The API also returns a next pageToken. The error only occurs when trying to send the request including the token.

FelixSche commented 12 months ago

Okay I just found out that pageToken is part of the searchbody and not of the optParameters. My bad. Maybe add this to the docs though. That was rather hard to figure out.