2

这是 ac# .NET 应用程序。该应用程序进行了一个经过 OAuth2 身份验证的 YouTube Data v3 ChannelList 查询,该查询已经运行了两个月。最近,查询失败并显示来自 Google 的 403 Forbidden 消息。它在我们的 Azure Web 服务器和在开发人员桌面上的 Visual Studio 中运行时失败。该查询至少对一个用户有效,但对所有其他测试的用户都失败。该查询(在此处列出)适用于 API Explorer 中的所有用户。我找不到从 Google 返回的其他错误描述。

更新(2013 年 7 月 15 日):在将 access_token 添加到查询后,查询现在运行。以前,它仅在 Service 对象中使用 access_token 成功执行,而不是查询的明确部分。尽管直接附加了 access_token 后查询成功,但我们在 YouTube 嵌入式播放器上收到了下游 JavaScript 错误。不确定这是否相关。我看到 6 月下旬有一个 .NET API 更新。@Ikailan,在谷歌做了一些改变来打破服务对象中的 access_token 身份验证。注意:我们确实更新了新的 API。是否需要更改我们的代码才能使用 2013 年 6 月的 API 更新?

错误消息“远程服务器返回错误:(403) Forbidden。”

失败但现在与添加到查询的 Auth 令牌一起使用的方法。

//Gets the channel information of the current user
public static ChannelListResponse GetCurrentUserChannel(string token)
{
    YouTubeService service = new YouTubeService(GlobalSettings.applicationName, GlobalSettings.developerKey);
    GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory("YouTube", GlobalSettings.applicationName);
    authFactory.Token = token;
    service.RequestFactory = authFactory;

    ChannelListResponse response = new ChannelListResponse();

    try
    {
        System.IO.Stream resultStream = service.Query(new Uri("https://www.googleapis.com/youtube/v3/channels?part=id%2Csnippet%2CcontentDetails%2Cstatistics%2CtopicDetails&mine=true&access_token=" + authFactory.Token));
        using (var reader = new System.IO.StreamReader(resultStream))
        {
            string value = reader.ReadToEnd();
            response = JObject.Parse(value).ToObject<ChannelListResponse>();
        }
    }
    catch (Exception ex) { }
    return response;
}

引发异常的行。添加了身份验证密钥(参见上面的代码)。现在查询成功执行。

System.IO.Stream resultStream = service.Query(new Uri("https://www.googleapis.com/youtube/v3/channels?part=id%2Csnippet&mine=true"));

但是,我们收到嵌入式 YouTube 视频播放器的访问被拒绝错误。

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in user code
Exception was thrown at line 4224, column 4 in http://localhost:49185/YotaCast_Prototype/Scripts/jquery-1.9.1.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4242, column 4 in http://localhost:49185/YotaCast_Prototype/Scripts/jquery-1.9.1.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 360, column 9 in http://localhost:49185/YotaCast_Prototype/Scripts/foundation/foundation.js
0x800a1391 - JavaScript runtime error: 'Zepto' is undefined
Exception was thrown at line 1, column 97 in http://s.ytimg.com/yts/jsbin/www-embed-player-vflXN6WzI.js
0x80070005 - JavaScript runtime error: Access is denied.
4

0 回答 0