October 22, 2024
Chicago 12, Melborne City, USA
PHP

Youtube Data API – Get private and unlisted Playlists


In a Laravel app, I am trying to get the playlists associated to my YouTube channel.
These playlists can be either public, private or unlisted.

I can retrive public playlists but I am stuggling to get the unlisted and private ones, even with oAuth configured.

Here is my code

public function getPlaylist()
    {

        $client = new Client();
        $client->setLogger(new \Monolog\Logger('google-api'));
        $client->setApplicationName('Playlists');


        $client->setAuthConfig(base_path('youtube.json'));

        // Exchange authorization code for an access token.
        if (Session::has('google_oauth_token')) {
            $client->setAccessToken(Session::get('google_oauth_token'));
        }

        $service = new YouTube($client);

        $queryParams = [
            'channelId' => config('scraper.channelId'),
            'maxResults' => 50,
            'mine' => 1,
        ];

        $response = $service->playlists->listPlaylists('snippet, contentDetails, status,id', $queryParams);


        dd($response);
    }

I get the following error:
{ "error": { "code": 400, "message": "Incompatible parameters specified in the request: channelId, mine", "errors": [ { "message": "Incompatible parameters specified in the request: channelId, mine", "domain": "youtube.parameter", "reason": "incompatibleParameters", "location": "parameters.", "locationType": "other" } ] } }

When I remove the mine parameter. I get the public playlists.
If I keep the mine parameter and remove the channelId, I get this error:
{ "error": { "code": 404, "message": "Channel not found.", "errors": [ { "message": "Channel not found.", "domain": "youtube.playlist", "reason": "channelNotFound", "location": "channelId", "locationType": "parameter" } ] } }

What am I doing wrong ? Is this even possible to get private and unlisted playlists?

Thank you for your assistance on this



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video