我嘗試使用youtube api v3和.NET上傳視頻到youtube,但它永遠掛着調用AuthorizeAsync。你可以看到代碼也在:https://developers.google.com/youtube/v3/code_samples/dotnetgoogleWebAuthorizationBroker.AuthorizeAsync永遠掛起
static void Main(string[] args)
{
Console.WriteLine("YouTube Data API: Upload Video");
Console.WriteLine("==============================");
try
{
new UploadVideo().Run().Wait();
}
catch (AggregateException ex)
{
foreach (var e in ex.InnerExceptions)
{
Console.WriteLine("Error: " + e.Message);
}
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
private async Task Run()
{
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
// This OAuth 2.0 access scope allows an application to upload files to the
// authenticated user's YouTube channel, but doesn't allow other types of access.
new[] { YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None
);
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
我一直在運行,但對我來說,這個問題是因爲當我使用IIS的方法,只是絞死。然後,我切換到IIS Express以獲取該令牌,並稍後在我的託管在IIS上的應用程序中使用它。 – 2015-12-30 14:07:43