I'm using this API to fetch all videos from my channel
but it can only get public videos. In Google developer page, I can authorize and get all videos but in my PHP code, I don't know how to do that. I tried to use curl but it didn't work. I think I must place access token somewhere but I don't know. Can anyone help me? Below is my code:
public function listVideos()
{
$apiKey = 'my_API_key';
$playlistId = 'my_playlist_id';
$token = $this->getAccessToken(); // custom from Youtube API code
$req = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId={$playlistId}&key={$apiKey}";
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $req,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0',
]);
$data = curl_exec($ch);
if ($data == false) {
$this->messages = ['error' => curl_error($ch)];
return $this->messages;
}
curl_close($ch);
return $data;
}