Set proxy for Google.Apis.YouTube.v3

后端 未结 1 2109
无人及你
无人及你 2021-01-28 13:38

I have the following bit of code to make a call to the

YouTubeService service = new YouTubeService(new BaseClientService.Initializer()
{
    ApiKey = AppSetting         


        
相关标签:
1条回答
  • 2021-01-28 14:25

    To get around this I had to make a webrequest to the url and map the result back to the VideoListResponse object:

    try
    {
        Uri api = new Uri(string.Format("https://www.googleapis.com/youtube/v3/videos?id={0}&key={1}&part=snippet,statistics", videoIds, AppSettings.Variables.YouTube_APIKey));
        WebRequest request = WebRequest.Create(api);
    
        WebProxy proxy = new WebProxy(AppSettings.Variables.ProxyAddress, AppSettings.Variables.ProxyPort);
        proxy.Credentials = new NetworkCredential(AppSettings.Variables.ProxyUsername, AppSettings.Variables.ProxyPassword, AppSettings.Variables.ProxyDomain);
        request.Proxy = proxy;
    
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
            {
                return JsonConvert.DeserializeObject<VideoListResponse>(streamReader.ReadToEnd());
            }
        }
    }
    catch (Exception ex)
    {
        ErrorLog.LogError(ex, "Video entity processing error: ");
    }
    
    0 讨论(0)
提交回复
热议问题