You are here

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

Make the API queries to get the data the parser needs.

Parameters

string $source: The URL source.

string $id: The feed Id.

Return value

string Returns a JSON-encoded array of stdClass objects.

1 call to FeedsYouTubeFetcher::get()
FeedsYouTubeFetcher::fetch in src/Feeds/Fetcher/FeedsYouTubeFetcher.php
Fetch content from a feed and return it.

File

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

Class

FeedsYouTubeFetcher
Constructs FeedsYouTubeFetcher object.

Namespace

Drupal\feeds_youtube\Feeds\Fetcher

Code

public function get(string $source, $id) {
  $client = $this
    ->getClientFactory($id);
  $youtube = new \Google_Service_YouTube($client);
  $number_of_pages = $this
    ->getConfiguration('import_video_limit');
  if ($number_of_pages < 1) {
    $number_of_pages = 1;
  }
  $result = [];
  $next_page_token = '';
  for ($i = 0; $i < $number_of_pages; $i++) {
    $api_request_result = $this
      ->requestNextPage($source, $next_page_token, $client, $youtube);
    $next_page_token = !empty($api_request_result['next_page_token']) ? $api_request_result['next_page_token'] : '';
    if (!empty($api_request_result['result'])) {
      $result = array_merge($result, $api_request_result['result']);
    }
  }
  return json_encode($result);
}