Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

Commonmark migration
Source Link

The reason why you get only 17 results is the order property of your request. If you remove this property you get many more results. The order='date' is not working as expected.

A little workaround (only example):

$DEVELOPER_KEY = 'THEKEY';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
//Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
try {
 // Call the search.list method to retrieve results matching the specified
 // query term.
 $searchResponse = $youtube->search->listSearch('id,snippet', array(
 'q' => $_GET['q'],
 'maxResults' => $_GET['maxResults'],
 'type' => 'video'
 ));
 function sortResponse($date1, $date2) {
 $date1 = new DateTime($date1['snippet']['publishedAt']);
 $date2 = new DateTime($date2['snippet']['publishedAt']);
 //"<" - sort DESC
 //">" - sort ASC
 return $date1 < $date2;
 }
 $items = $searchResponse['items'];
 usort($items, "sortResponse");
 //now your sorted items are in $items...
}

You can merge all your repsonse items in one array and use the custom sort function to get the order by publishAt.

API Document:
https://developers.google.com/youtube/v3/docs/search/list?hl=de#parameters

Related Question:
When I use order-date in youtube api then there are total results but items are not found

The reason why you get only 17 results is the order property of your request. If you remove this property you get many more results. The order='date' is not working as expected.

A little workaround (only example):

$DEVELOPER_KEY = 'THEKEY';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
//Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
try {
 // Call the search.list method to retrieve results matching the specified
 // query term.
 $searchResponse = $youtube->search->listSearch('id,snippet', array(
 'q' => $_GET['q'],
 'maxResults' => $_GET['maxResults'],
 'type' => 'video'
 ));
 function sortResponse($date1, $date2) {
 $date1 = new DateTime($date1['snippet']['publishedAt']);
 $date2 = new DateTime($date2['snippet']['publishedAt']);
 //"<" - sort DESC
 //">" - sort ASC
 return $date1 < $date2;
 }
 $items = $searchResponse['items'];
 usort($items, "sortResponse");
 //now your sorted items are in $items...
}

You can merge all your repsonse items in one array and use the custom sort function to get the order by publishAt.

API Document:
https://developers.google.com/youtube/v3/docs/search/list?hl=de#parameters

Related Question:
When I use order-date in youtube api then there are total results but items are not found

The reason why you get only 17 results is the order property of your request. If you remove this property you get many more results. The order='date' is not working as expected.

A little workaround (only example):

$DEVELOPER_KEY = 'THEKEY';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
//Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
try {
 // Call the search.list method to retrieve results matching the specified
 // query term.
 $searchResponse = $youtube->search->listSearch('id,snippet', array(
 'q' => $_GET['q'],
 'maxResults' => $_GET['maxResults'],
 'type' => 'video'
 ));
 function sortResponse($date1, $date2) {
 $date1 = new DateTime($date1['snippet']['publishedAt']);
 $date2 = new DateTime($date2['snippet']['publishedAt']);
 //"<" - sort DESC
 //">" - sort ASC
 return $date1 < $date2;
 }
 $items = $searchResponse['items'];
 usort($items, "sortResponse");
 //now your sorted items are in $items...
}

You can merge all your repsonse items in one array and use the custom sort function to get the order by publishAt.

API Document:
https://developers.google.com/youtube/v3/docs/search/list?hl=de#parameters

Related Question:
When I use order-date in youtube api then there are total results but items are not found

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

The reason why you get only 17 results is the order property of your request. If you remove this property you get many more results. The order='date' is not working as expected.

A little workaround (only example):

$DEVELOPER_KEY = 'THEKEY';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
//Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
try {
 // Call the search.list method to retrieve results matching the specified
 // query term.
 $searchResponse = $youtube->search->listSearch('id,snippet', array(
 'q' => $_GET['q'],
 'maxResults' => $_GET['maxResults'],
 'type' => 'video'
 ));
 function sortResponse($date1, $date2) {
 $date1 = new DateTime($date1['snippet']['publishedAt']);
 $date2 = new DateTime($date2['snippet']['publishedAt']);
 //"<" - sort DESC
 //">" - sort ASC
 return $date1 < $date2;
 }
 $items = $searchResponse['items'];
 usort($items, "sortResponse");
 //now your sorted items are in $items...
}

You can merge all your repsonse items in one array and use the custom sort function to get the order by publishAt.

API Document:
https://developers.google.com/youtube/v3/docs/search/list?hl=de#parameters

Related Question:
When I use order-date in youtube api then there are total results but items are not found When I use order-date in youtube api then there are total results but items are not found

The reason why you get only 17 results is the order property of your request. If you remove this property you get many more results. The order='date' is not working as expected.

A little workaround (only example):

$DEVELOPER_KEY = 'THEKEY';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
//Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
try {
 // Call the search.list method to retrieve results matching the specified
 // query term.
 $searchResponse = $youtube->search->listSearch('id,snippet', array(
 'q' => $_GET['q'],
 'maxResults' => $_GET['maxResults'],
 'type' => 'video'
 ));
 function sortResponse($date1, $date2) {
 $date1 = new DateTime($date1['snippet']['publishedAt']);
 $date2 = new DateTime($date2['snippet']['publishedAt']);
 //"<" - sort DESC
 //">" - sort ASC
 return $date1 < $date2;
 }
 $items = $searchResponse['items'];
 usort($items, "sortResponse");
 //now your sorted items are in $items...
}

You can merge all your repsonse items in one array and use the custom sort function to get the order by publishAt.

API Document:
https://developers.google.com/youtube/v3/docs/search/list?hl=de#parameters

Related Question:
When I use order-date in youtube api then there are total results but items are not found

The reason why you get only 17 results is the order property of your request. If you remove this property you get many more results. The order='date' is not working as expected.

A little workaround (only example):

$DEVELOPER_KEY = 'THEKEY';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
//Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
try {
 // Call the search.list method to retrieve results matching the specified
 // query term.
 $searchResponse = $youtube->search->listSearch('id,snippet', array(
 'q' => $_GET['q'],
 'maxResults' => $_GET['maxResults'],
 'type' => 'video'
 ));
 function sortResponse($date1, $date2) {
 $date1 = new DateTime($date1['snippet']['publishedAt']);
 $date2 = new DateTime($date2['snippet']['publishedAt']);
 //"<" - sort DESC
 //">" - sort ASC
 return $date1 < $date2;
 }
 $items = $searchResponse['items'];
 usort($items, "sortResponse");
 //now your sorted items are in $items...
}

You can merge all your repsonse items in one array and use the custom sort function to get the order by publishAt.

API Document:
https://developers.google.com/youtube/v3/docs/search/list?hl=de#parameters

Related Question:
When I use order-date in youtube api then there are total results but items are not found

Bounty Awarded with 25 reputation awarded by Community Bot
Source Link
Sebastian Brosch
  • 43.8k
  • 15
  • 78
  • 89

The reason why you get only 17 results is the order property of your request. If you remove this property you get many more results. The order='date' is not working as expected.

A little workaround (only example):

$DEVELOPER_KEY = 'THEKEY';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
//Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
try {
 // Call the search.list method to retrieve results matching the specified
 // query term.
 $searchResponse = $youtube->search->listSearch('id,snippet', array(
 'q' => $_GET['q'],
 'maxResults' => $_GET['maxResults'],
 'type' => 'video'
 ));
 function sortResponse($date1, $date2) {
 $date1 = new DateTime($date1['snippet']['publishedAt']);
 $date2 = new DateTime($date2['snippet']['publishedAt']);
 //"<" - sort DESC
 //">" - sort ASC
 return $date1 < $date2;
 }
 $items = $searchResponse['items'];
 usort($items, "sortResponse");
 //now your sorted items are in $items...
}

You can merge all your repsonse items in one array and use the custom sort function to get the order by publishAt.

API Document:
https://developers.google.com/youtube/v3/docs/search/list?hl=de#parameters

Related Question:
When I use order-date in youtube api then there are total results but items are not found

lang-php

AltStyle によって変換されたページ (->オリジナル) /