尝试将视频上传到我的 youtube 频道时出现以下错误:
System.ArgumentException: Precondition failed.: !string.IsNullOrEmpty(authorization.RefreshToken)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) at Microsoft.Runtime。 CompilerServices.TaskAwaiter.ValidateEnd(Task task) 在 Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable 1.ConfiguredTaskAwaiter.GetResult()
at Google.Apis.Upload.ResumableUpload
1.d__0.MoveNext() 在 c:\code.google.com\google-api-dotnet-client\default_3\Tools\Google.Apis。 Release\bin\Debug\output\default\Src\GoogleApis\Apis[媒体]\Upload\ResumableUpload.cs:356行
编码:
class Program
{
private const string SERVICE_ACCOUNT_EMAIL = "685082793570-acspgovnpo2dfmcb5fsqdu5e0q7pdmn1@developer.gserviceaccount.com";
private const string SERVICE_ACCOUNT_PKCS12_FILE_PATH = @"97b6020dc5777485250124e25b788e4b8ed3324e-privatekey.p12";
static YouTubeService BuildService()
{
var certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret",X509KeyStorageFlags.Exportable);
var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
{
ServiceAccountId = SERVICE_ACCOUNT_EMAIL,
Scope = YouTubeService.Scopes.YoutubeUpload.GetStringValue() };
var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);
return new YouTubeService((new BaseClientService.Initializer()
{
Authenticator = auth,
ApplicationName = "Drive API Sample",
}));
}
static void Main(string[] args)
{
var youtube = BuildService();
var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = "Video title";
video.Snippet.Description = "Video description";
video.Snippet.Tags = new string[] { "tag1", "tag2" };
video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "public"; // "Video privacy (public, private, or unlisted)";
var filePath = "52224a59-2029-43fd-806b-efc434256c25.mp4";
var fileStream = new FileStream(filePath, FileMode.Open);
var videosInsertRequest = youtube.Videos.Insert(video, "snippet,status", fileStream, "video/*");
var upload = videosInsertRequest.Upload();
Console.WriteLine(upload.BytesSent);
Console.WriteLine(upload.Status);
Console.WriteLine(upload.Exception);
}
}
任何想法为什么会发生这种情况?
我正在使用 Google.Apis DotNetOpenAuth 版本的 1.5.0.28972 版本:4.0.0.11165