views:

318

answers:

1

I'm trying to use YouTube API to upload videos from browser. I read Google API documentation and wrote this piece of code:

 public static YouTubeRequest GetRequest()
    {
        var request = HttpContext.Current.Session["YTRequest"] as YouTubeRequest;
        if (request == null)
        {
            var settings = new YouTubeRequestSettings("WebApp", "NA", ConfigurationManager.AppSettings["YouTubeAPIDeveloperKey"]);

            settings.AutoPaging = true;
            request = new YouTubeRequest(settings);
            HttpContext.Current.Session["YTRequest"] = request;
        }
        return request;
    }

var youTubeRequest = GetRequest();
var newVideo = new Video { Title = "Title", Description = "Description" };
newVideo.YouTubeEntry.Private = false;

var token = youTubeRequest.CreateFormUploadToken(newVideo);
var postUrl = token.Url;
var tokenValue = token.Token;

But I always receive this error message: The remote server returned an error: (401) Unauthorized.

on this line:

var token = youTubeRequest.CreateFormUploadToken(newVideo);

I think my issue is not related to Developer API key. It is correctly grabbed from API Dashboard.

Any idea?

+1  A: 

I found the problem myself!

newVideo.Keywords = "some keywords";

is required and you should send it.

Please note, I explained before that I changed YouTubeRequest parameters to get rid of 401 error message (see my own comments).

Mahdi