You are here

public function FeedsYouTubeFetcher::requestUrl in Feeds: YouTube Parser 8

Request URL.

Parameters

string $url: The URL to request.

string $page_token: The page token for the request.

Return value

array|null

1 call to FeedsYouTubeFetcher::requestUrl()
FeedsYouTubeFetcher::requestNextPage in src/Feeds/Fetcher/FeedsYouTubeFetcher.php
Perform API request to YouTube API and retrieve search result.

File

src/Feeds/Fetcher/FeedsYouTubeFetcher.php, line 265

Class

FeedsYouTubeFetcher
Constructs FeedsYouTubeFetcher object.

Namespace

Drupal\feeds_youtube\Feeds\Fetcher

Code

public function requestUrl($url, $page_token = '') {
  try {
    $url .= '&maxResults=' . $this
      ->getConfiguration('results_per_page');
    $url .= $page_token != '' ? '&pageToken=' . $page_token : '';
    $api_request_result = \Drupal::httpClient()
      ->get($url);
    $data = (string) $api_request_result
      ->getBody();
    return json_decode($data, TRUE);
  } catch (RequestException $e) {
    \Drupal::messenger()
      ->addError($this
      ->t('Request Error: @message', [
      '@message' => $e
        ->getMessage(),
    ]));
  }
}