6

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?

1
  • We can set a video as unlisted while uploading new one.Please follow the given link: Click here to see the article Commented Jul 6, 2012 at 6:31

3 Answers 3

7

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!

Sign up to request clarification or add additional context in comments.

1 Comment

This is now in the official downloadable API .
2

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!

1 Comment

We can set a video as unlisted while uploading new one.Please follow the given link: Click here to see the article
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.