Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Get list of all Unlisted videos using API? #303

Open
venkatasivaramireddy opened this issue Oct 5, 2020 · 6 comments
Open

How to Get list of all Unlisted videos using API? #303

venkatasivaramireddy opened this issue Oct 5, 2020 · 6 comments

Comments

@venkatasivaramireddy
Copy link

venkatasivaramireddy commented Oct 5, 2020

I was Tryied as like
https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId={}&type=video&forMine=true&order=date&maxResults=5&key={}

in responses:

{
"error": {
"code": 400,
"message": "The request contains an invalid combination of search filters and/or restrictions. Note that you must set the \u003ccode\u003etype\u003c/code\u003e parameter to \u003ccode\u003evideo\u003c/code\u003e if you set either the \u003ccode\u003eforContentOwner\u003c/code\u003e or \u003ccode\u003eforMine\u003c/code\u003e parameters to \u003ccode\u003etrue\u003c/code\u003e. You must also set the \u003ccode\u003etype\u003c/code\u003e parameter to \u003ccode\u003evideo\u003c/code\u003e if you set a value for the \u003ccode\u003eeventType\u003c/code\u003e, \u003ccode\u003evideoCaption\u003c/code\u003e, \u003ccode\u003evideoCategoryId\u003c/code\u003e, \u003ccode\u003evideoDefinition\u003c/code\u003e, \u003ccode\u003evideoDimension\u003c/code\u003e, \u003ccode\u003evideoDuration\u003c/code\u003e, \u003ccode\u003evideoEmbeddable\u003c/code\u003e, \u003ccode\u003evideoLicense\u003c/code\u003e, \u003ccode\u003evideoSyndicated\u003c/code\u003e, or \u003ccode\u003evideoType\u003c/code\u003e parameters.",
"errors": [
{
"message": "The request contains an invalid combination of search filters and/or restrictions. Note that you must set the \u003ccode\u003etype\u003c/code\u003e parameter to \u003ccode\u003evideo\u003c/code\u003e if you set either the \u003ccode\u003eforContentOwner\u003c/code\u003e or \u003ccode\u003eforMine\u003c/code\u003e parameters to \u003ccode\u003etrue\u003c/code\u003e. You must also set the \u003ccode\u003etype\u003c/code\u003e parameter to \u003ccode\u003evideo\u003c/code\u003e if you set a value for the \u003ccode\u003eeventType\u003c/code\u003e, \u003ccode\u003evideoCaption\u003c/code\u003e, \u003ccode\u003evideoCategoryId\u003c/code\u003e, \u003ccode\u003evideoDefinition\u003c/code\u003e, \u003ccode\u003evideoDimension\u003c/code\u003e, \u003ccode\u003evideoDuration\u003c/code\u003e, \u003ccode\u003evideoEmbeddable\u003c/code\u003e, \u003ccode\u003evideoLicense\u003c/code\u003e, \u003ccode\u003evideoSyndicated\u003c/code\u003e, or \u003ccode\u003evideoType\u003c/code\u003e parameters.",
"domain": "youtube.search",
"reason": "invalidSearchFilter",
"location": "parameters.",
"locationType": "other"
}
]
}
}

Anyone give me a solution for How to Get a list of all Unlisted videos from Youtube using API?

@samsermolla
Copy link

You can get unlisted videos without going the OAuth route using an API key though many online say you cannot. Here is what I found:

Go to https://console.developers.google.com and create an API key for Youtube Data API v3. API key, NOT OAuth ClientId. Your API key should look something like "AISdkJKdk7GuSkDKJDKSkLmSSdDFm4ro4E_4et_ww"

If using C# Download Google.Apis.YouTube.v3 Version 1.40.2.1593 from Nuget. If not download the equivalent library for your language.

Next go to your You Tube account and create a new playlist called "Unlisted Videos returned by API Key" (In YouTube studio if you edit a video you already have uploaded there is a drop down menu for Playlist where you can assign one that already exists or create a new one)

Then go to your channel, and click the playlist tab. Edit the new playlist you just created so that it is Unlisted or else your Unlisted videos you add to this playlist will be visible on the UI of your channel.

On your channel find the playlist you created again and click to view it. The URL you are taken to will have a &list query string parameter and you need to get that Id. Example: https://www.youtube.com/watch?v=kskScbSkdSDg&list=DKfiVi8sZdkZqW-saZt7bN8DDTDxshjDK. In this example our list (PlalistId) value is DKfiVi8sZdkZqW-saZt7bN8DDTDxshjDK which will be needed when calling our GetPlaylistVideos method.

Now you have the pre-requisites done. Time for the code:

  • public static List GetPlaylistVideos(string PlaylistId) { List result = new List(); try { YouTubeService service = new YouTubeService(new BaseClientService.Initializer() { ApplicationName = YOUTUBE_APPLICATION_NAME, ApiKey = YOUTUBE_API_KEY }); var nextPageToken = ""; while (nextPageToken != null) { var playlistItemsListRequest = service.PlaylistItems.List("snippet"); playlistItemsListRequest.PlaylistId = PlaylistId; playlistItemsListRequest.MaxResults = 50; playlistItemsListRequest.PageToken = nextPageToken; // Retrieve the list of videos uploaded to the authenticated user's channel. var playlistItemsListResponse = playlistItemsListRequest.Execute(); foreach (var playlistItem in playlistItemsListResponse.Items) { YouTubeVideo v = new YouTubeVideo { EmbedUrl = String.Format("https://www.youtube.com/embed/{0}", playlistItem.Snippet.ResourceId.VideoId), Title = playlistItem.Snippet.Title, Description = playlistItem.Snippet.Description, ThumbnailUrl = playlistItem.Snippet.Thumbnails.High.Url }; result.Add(v); } nextPageToken = playlistItemsListResponse.NextPageToken; } }

If you call the GetPlaylistVideos you will see it returns the unlisted videos from your unlisted playlist using an API key and not OAuth.

@samsermolla
Copy link

For more solutions contact with me email : [email protected]

@venkatasivaramireddy
Copy link
Author

Thanks, samsermolla

but without creating the playlist we have any solution?

@venkatasivaramireddy
Copy link
Author

Any solution to my Question?

without creating the playlist we have any solution to get Youtube Unlisted Videos?

@davisj95
Copy link

davisj95 commented Jun 1, 2021

Did you ever get this figured out? I have the same question

@mazharfarid
Copy link

I am getting lists of all playlists while I needed only unlisted playlists in asp.net core. Anyone can help me please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants