使用谷歌api或任何其他方法从特定范围获取youtube频道视频



我尝试使用谷歌api从播放列表中获取youtube视频。它成功了。但我最多可以获得50个视频。我需要做的是,获取50多个或从范围内获取最旧的视频。

就像我们可以在mysql中限制结果一样。

语言(PHP和Java脚本(

我的工作代码

<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for youtube.playlistItems.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function loadClient() {
gapi.client.setApiKey("MY_API_KEY");
return gapi.client.load("https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded before calling this method.
function execute() {
return gapi.client.youtube.playlistItems.list({
"part": "snippet,contentDetails",
"maxResults": 50,
"playlistId": "PLAY_LIST_ID"
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client");
</script>

我阅读了谷歌api文档,并没有得到明确的答案。请不要结束提问。我需要明确的答案。


<?php
class GAPI{
private $appName    = "Get Play List Info";
private $apiKey     = 'YOUR_API_KEY';
private $maxResult  = NULL; //0-50
private $playlistId = NULL;
private $nextPageToken  = NULL;
private $prevPageToken  = NULL;
private $service;
private $client;
public function __construct($playlistId,$maxResult=10){
$this->init(); //Initiate function
$this->client = new Google_Client(); //Create object from Google Client class
$this->playlistId = $playlistId; //Set play list id
$this->maxResult  = $maxResult; //Set max results
$this->client->setApplicationName($this->appName);
$this->client->setDeveloperKey($this->apiKey);
// Define service object for making API requests.
$this->service = new Google_Service_YouTube($this->client);
}
//Initiate
private function init(){
if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
throw new Exception(sprintf('Please run "composer require google/apiclient:~2.0" in "%s"', __DIR__));
}
require_once __DIR__ . '/vendor/autoload.php';
}
public function getItems($nextPageToken=NULL,$prevPageToken=NULL){
$this->nextPageToken = isset($nextPageToken) ? $nextPageToken : NULL;
$this->prevPageToken = isset($prevPageToken) ? $prevPageToken : NULL;
$queryParams = [
'maxResults' => $this->maxResult,
'playlistId' => $this->playlistId,
'pageToken'  => $this->nextPageToken
];
$response = $this->service->playlistItems->listPlaylistItems('contentDetails', $queryParams);
return $response;
}
}
?>

最新更新