本文介绍了尝试使用Google API v3检索我的youtube视频上传列表时,请求后是否不继续?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
该程序只是在尝试发出请求后挂起,并且从不继续.尝试使用try和ctach,但不会引发任何异常或错误.
The program just hang after trying to make a request and never continue.Tried to use try and ctach but it's not throwing any exceptions or errors.
这是我在新课程中的代码:
This is my code in a new class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
namespace Youtube
{
class Youtube_Retrieve_Uploads
{
public Youtube_Retrieve_Uploads()
{
try
{
Run().Wait();
}
catch (AggregateException ex)
{
foreach (var e in ex.InnerExceptions)
{
Console.WriteLine("Error: " + e.Message);
}
}
}
private async Task Run()
{
UserCredential credential;
using (var stream = new FileStream(@"C:\jason file\client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
// This OAuth 2.0 access scope allows for read-only access to the authenticated
// user's account, but not other types of account access.
new[] { YouTubeService.Scope.YoutubeReadonly },
"user",
CancellationToken.None,
new FileDataStore(this.GetType().ToString())
);
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = this.GetType().ToString()
});
var channelsListRequest = youtubeService.Channels.List("contentDetails");
channelsListRequest.Mine = true;
// Retrieve the contentDetails part of the channel resource for the authenticated user's channel.
var channelsListResponse = await channelsListRequest.ExecuteAsync();
foreach (var channel in channelsListResponse.Items)
{
// From the API response, extract the playlist ID that identifies the list
// of videos uploaded to the authenticated user's channel.
var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;
Console.WriteLine("Videos in list {0}", uploadsListId);
var nextPageToken = "";
while (nextPageToken != null)
{
var playlistItemsListRequest = youtubeService.PlaylistItems.List("snippet");
playlistItemsListRequest.PlaylistId = uploadsListId;
playlistItemsListRequest.MaxResults = 50;
playlistItemsListRequest.PageToken = nextPageToken;
// Retrieve the list of videos uploaded to the authenticated user's channel.
var playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();
foreach (var playlistItem in playlistItemsListResponse.Items)
{
// Print information about each video.
Console.WriteLine("{0} ({1})", playlistItem.Snippet.Title, playlistItem.Snippet.ResourceId.VideoId);
}
nextPageToken = playlistItemsListResponse.NextPageToken;
}
}
}
}
}
我使用了一个断点,当它在做直线时:
I used a break point and when it's doing the line:
var channelsListResponse = await channelsListRequest.ExecuteAsync();
它只是挂了程序,所以永远不会继续.
It's just hanging the program never continue.
推荐答案
我承认这不是理想的解决方案,而是可能的解决方案之一,但就我而言,我已经删除了"await"和* Async()关键字,并且现在可以使用.
I admit that it's not ideal solution rather one of possible but, in my case, I have removed "await" and *Async() keywords and it works now.
var channelsListResponse = channelsListRequest.Execute();
代替
var channelsListResponse = await channelsListRequest.ExecuteAsync();
还有
var playlistItemsListResponse = playlistItemsListRequest.Execute();
代替
var playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();
这篇关于尝试使用Google API v3检索我的youtube视频上传列表时,请求后是否不继续?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!