设置Google.Apis.YouTube.v3的代理

皮特

我有以下代码可以调用

YouTubeService service = new YouTubeService(new BaseClientService.Initializer()
{
    ApiKey = AppSettings.Variables.YouTube_APIKey,
    ApplicationName = AppSettings.Variables.YouTube_AppName
});

Google.Apis.YouTube.v3.VideosResource.ListRequest request = service.Videos.List("snippet,statistics");
request.Id = string.Join(",", videoIDs);
VideoListResponse response = request.Execute();

所有这些都有效,但是当我们将其部署到实时服务器中时,它需要通过代理才能获取,因此我们将以下内容放入web.config中:

    <defaultProxy useDefaultCredentials="false" enabled="true">
        <proxy usesystemdefault="False" proxyaddress="http://192.111.111.102:8081" />
    </defaultProxy>

但是,这似乎不起作用,因为在进行呼叫时,出现以下错误:

System.Net.Sockets.SocketException:无法建立连接,因为目标计算机主动拒绝它216.58.213.74:443

有没有办法在代码中手动设置代理?

类似于以下内容:

WebProxy proxy = new WebProxy("192.111.111.102", 8081);
proxy.Credentials = new NetworkCredential(AppSettings.Variables.ProxyUser, AppSettings.Variables.ProxyPassword, AppSettings.Variables.ProxyDomain);

// apply this to the service or request object here
皮特

为了解决这个问题,我必须对url进行webrequest并将结果映射回该VideoListResponse对象:

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: ");
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用C#和Google.Apis.YouTube.v3列出YouTube视频

来自分类Dev

名称空间“ Google.Apis.Youtube.v3”中不存在“ YoutubeService”

来自分类Dev

Google.Apis.YouTube.v3 编译频道统计失败“The uri string is too long”

来自分类Dev

Youtube V3 API-如何设置APIKey

来自分类Dev

Youtube V3 API-如何设置APIKey

来自分类Dev

Google Youtube API V3只获取数据

来自分类Dev

在 C#.Net 中将 ParentReference 从 Google Drive APIs v2 迁移到 v3

来自分类Dev

在 C# .Net 中将 QuotaBytesTotal/ QuotaBytesUsed 从 Google Drive APIs v2 迁移到 v3

来自分类Dev

设置实时事件的contentDetails时出错-Youtube Live API v3

来自分类Dev

使用forMine设置为false进行搜索时,youtube v3 api错误

来自分类Dev

将视频设置为youtube data api v3中的收藏夹

来自分类Dev

如何使用Google API PHP客户端库和Youtube API V3将视频上传到YouTube?

来自分类Dev

YouTube数据API(v3):YouTube的Google OAuth2授权是否可以上载检索?

来自分类Dev

YouTube数据API(v3):YouTube的Google OAuth2授权是否可以上载检索?

来自分类Dev

在Google Developers Console中找不到YouTube Data API v3

来自分类Dev

如何使用YouTube API V3?

来自分类Dev

Youtube v3 API视频语言

来自分类Dev

Youtube API V3和Etag

来自分类Dev

Youtube API v3 .NET集成

来自分类Dev

页面令牌youtube api v3

来自分类Dev

YouTube API v3获取评论

来自分类Dev

youtube数据API v3搜索

来自分类Dev

Youtube API V3和Etag

来自分类Dev

YouTube iframe API v3限制

来自分类Dev

Gwt YouTube数据API v3

来自分类Dev

Youtube API v3获得评论

来自分类Dev

Youtube api v3添加评论

来自分类Dev

解析 youtube 数据 v3 api

来自分类Dev

通过HTTP POST的YouTube API v3:上传视频时无法设置摘要(标题最终显示为“未知”)

Related 相关文章

  1. 1

    使用C#和Google.Apis.YouTube.v3列出YouTube视频

  2. 2

    名称空间“ Google.Apis.Youtube.v3”中不存在“ YoutubeService”

  3. 3

    Google.Apis.YouTube.v3 编译频道统计失败“The uri string is too long”

  4. 4

    Youtube V3 API-如何设置APIKey

  5. 5

    Youtube V3 API-如何设置APIKey

  6. 6

    Google Youtube API V3只获取数据

  7. 7

    在 C#.Net 中将 ParentReference 从 Google Drive APIs v2 迁移到 v3

  8. 8

    在 C# .Net 中将 QuotaBytesTotal/ QuotaBytesUsed 从 Google Drive APIs v2 迁移到 v3

  9. 9

    设置实时事件的contentDetails时出错-Youtube Live API v3

  10. 10

    使用forMine设置为false进行搜索时,youtube v3 api错误

  11. 11

    将视频设置为youtube data api v3中的收藏夹

  12. 12

    如何使用Google API PHP客户端库和Youtube API V3将视频上传到YouTube?

  13. 13

    YouTube数据API(v3):YouTube的Google OAuth2授权是否可以上载检索?

  14. 14

    YouTube数据API(v3):YouTube的Google OAuth2授权是否可以上载检索?

  15. 15

    在Google Developers Console中找不到YouTube Data API v3

  16. 16

    如何使用YouTube API V3?

  17. 17

    Youtube v3 API视频语言

  18. 18

    Youtube API V3和Etag

  19. 19

    Youtube API v3 .NET集成

  20. 20

    页面令牌youtube api v3

  21. 21

    YouTube API v3获取评论

  22. 22

    youtube数据API v3搜索

  23. 23

    Youtube API V3和Etag

  24. 24

    YouTube iframe API v3限制

  25. 25

    Gwt YouTube数据API v3

  26. 26

    Youtube API v3获得评论

  27. 27

    Youtube api v3添加评论

  28. 28

    解析 youtube 数据 v3 api

  29. 29

    通过HTTP POST的YouTube API v3:上传视频时无法设置摘要(标题最终显示为“未知”)

热门标签

归档