これは ac# .NET アプリケーションです。このアプリは、2 か月間機能していた OAuth2 認証済みの YouTube データ v3 ChannelList クエリを作成します。最近、Google からの 403 Forbidden メッセージでクエリが失敗します。Azure Web サーバーから、および開発者デスクトップの Visual Studio で実行すると失敗します。クエリは少なくとも 1 人のユーザーに対して機能しますが、テストされた他のすべてのユーザーに対しては失敗します。クエリ (ここにリストされています) は、API Explorer 内のすべてのユーザーに対して機能します。Google から返された追加のエラーの説明が見つかりません。
更新 (2013 年 7 月 15 日): クエリは、access_token をクエリに追加した後に実行されるようになりました。以前は、明示的にクエリの一部ではなく、Service オブジェクトでのみ access_token を使用して正常に実行されました。access_token を直接追加するとクエリは成功しますが、YouTube 埋め込みプレーヤーでダウンストリーム JavaScript エラーが発生します。それが関連しているかどうかはわかりません。6 月下旬に .NET API の更新があったようです。@Ikailan は、Service オブジェクトの access_token 認証を破るために、Google で何か変更を行いました。注: 新しい 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 ビデオ プレーヤーで Access Denied エラーが発生します。
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.