我正在尝试使用 YouTube API 从浏览器上传视频。我阅读了 Google API 文档并编写了这段代码:
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;
但我总是收到此错误消息:远程服务器返回错误:(401)未经授权。
在这条线上:
var token = youTubeRequest.CreateFormUploadToken(newVideo);
我认为我的问题与开发人员 API 密钥无关。它是从 API Dashboard 正确获取的。
任何的想法?