我使用YouTube的API上传视频。但是,我的YouTube帐户有两个频道,我只能成功上传到主频道,而不是第二频道。
有谁能告诉我上传到第二个频道需要做什么?
private async Task Run(String title,String mota,String[] tag,String filepath)
{
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.YoutubeUpload},
"user",
CancellationToken.None
);
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
var video = new Google.Apis.YouTube.v3.Data.Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = title;
video.Snippet.Description = mota;
video.Snippet.Tags = tag;
video.Snippet.CategoryId = "22";
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "unlisted";
var filePath = filepath;
using (var fileStream = new FileStream(filePath, FileMode.Open))
{
var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
await videosInsertRequest.UploadAsync();
}
}
答案 0 :(得分:0)
您必须在OAuth流程中授权正确的帐户。如果红色圈出的第二个帐户是CMS帐户,则必须在API调用中使用onBehalfOfContentOwner
参数。有些通话还有forUsername
参数,允许您通过提供用户名代表用户拨打电话。
例如,channels.list mehtod同时包含onBehalfOfContentOwner
参数和forUsername
参数。