Reputation: 121
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?
Upvotes: 6
Views: 3662
Reputation: 319
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.
Upvotes: 2
Reputation: 648
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!
Upvotes: 7
Reputation: 2736
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!
Upvotes: 2