It seems the Youtube API for .net hasn't been updated in a while. As such there is no property or method exposed to set a video as unlisted. Could someone suggest a work around if they have come across this issue before?
Stay organized with collections Save and categorize content based on your preferences. This guide provides and explains a Python script that uploads a YouTube video using the YouTube Data API. The code uses the Google APIs Client Library for Python.
Everyone can change this setting to make their video public, private, or unlisted. Save or publish: To publish your video now, choose this option and select Private, Unlisted, or Public as your video's privacy setting. If you choose to make your video public, you can also set your video as an instant Premiere.
I was having trouble figuring this out too, so thought I would post my findings for anybody looking for an answer to this.
As per this thread, support for yt:accessControl was added in rev. 1118.
At the time of this writing, that revision is not included in the API that you download from Google's API download page. You have to get the very latest version of the API here (SVN Checkout).
Once you have that in place, you can do something like this:
Video newVideo = new Video();
newVideo.YouTubeEntry.AccessControls.Add(new YtAccessControl("list", "denied"));
Cheers!
This post was a big help for me:
How do I disable comments and ratings using the YouTube API asp.net
I ended up having to modify the code to add a null check for the Attributes list:
private Video SetAcessControl(Video video, string type, string permission)
{
var exts = video.YouTubeEntry.ExtensionElements
.Where(x => x is XmlExtension)
.Select(x => x as XmlExtension)
.Where(x => x.Node.Attributes != null && x.Node.Attributes["action"] != null && x.Node.Attributes["action"].InnerText == type);
var ext = exts.FirstOrDefault();
if (ext != null) ext.Node.Attributes["permission"].InnerText = permission;
return video;
}
Then, to use it:
YouTubeRequest request = CreateYouTubeRequest(configuration);
Uri youTubeUrl = new Uri(string.Format("http://gdata.youtube.com/feeds/api/users/default/uploads/{0}", youTubeVideoId));
Video video = request.Retrieve<Video>(youTubeUrl);
video = SetAcessControl(video, "list", "denied"); // removes the video from searches, thus making it Unlisted (what you're looking for)
video = SetAcessControl(video, "comment", "denied"); // disables comments
video = SetAcessControl(video, "commentVote", "denied"); // disables voting on comments
video = SetAcessControl(video, "videoRespond", "denied"); // disables video responses
video = SetAcessControl(video, "rate", "denied"); // disables rating
Video updatedVideo = request.Update(video);
It is very important to note that this cannot be applied on a video you're uploading (i.e. you can't apply it to a new Video() before calling request.Upload(video). You need to wait until after the upload process has completed before this code will work.
To see a full list of the items you can disable using this method, see this url: http://code.google.com/apis/youtube/2.0/reference.html#youtube_data_api_tag_yt:accessControl
Hope this helps!
Pass username and password with your "YouTubeRequestSettings
".
Example
YouTubeRequestSettings settings = new YouTubeRequestSettings("My Channel", YouTubeDeveloperKey, "username", "password");
If you want to retrieve "unlisted" or "private" videos you need to pass authentication with your request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With