我目前正在使用vb.net从twitch api中提取一些频道信息。 这很成功..有时候。 其他时候我得到关于频道的一半数据。
以下是我的代码的相关摘要
Dim json As String = GetHTML(New Uri("https://api.twitch.tv/kraken/streams?channel=" & channels & "&limit=1000"))
Dim root As JObject = JObject.Parse(json)
Dim follows As JToken = root("streams")
For Each twitch_name As JToken In follows
Dim name As String = twitch_name("channel")("display_name").ToString()
Dim viewers As String = twitch_name("viewers")
Dim partner As String = "False"
Dim status As String = "Unknown"
Dim cover As String = "http://static-cdn.jtvnw.net/ttv-boxart/Unknown-92x128.jpg"
'Added this to band-aid the issue
If twitch_name("channel")("partner") Then
partner = twitch_name("channel")("partner").ToString()
status = twitch_name("channel")("status").ToString()
cover = "http://static-cdn.jtvnw.net/ttv-boxart/" & twitch_name("channel")("game").ToString() & "-92x128.jpg"
End If
'Do stuff with that info
Next
正如我之前所说,这项工作大部分时间都完美无瑕。但有时候因为一些奇怪的原因而忽略了频道数据。
以下是频道json应该是什么样的
"channel": {
"_links": {
"self": "https://api.twitch.tv/kraken/channels/official_don_gaming",
"follows": "https://api.twitch.tv/kraken/channels/official_don_gaming/follows",
"commercial": "https://api.twitch.tv/kraken/channels/official_don_gaming/commercial",
"stream_key": "https://api.twitch.tv/kraken/channels/official_don_gaming/stream_key",
"chat": "https://api.twitch.tv/kraken/chat/official_don_gaming",
"features": "https://api.twitch.tv/kraken/channels/official_don_gaming/features",
"subscriptions": "https://api.twitch.tv/kraken/channels/official_don_gaming/subscriptions",
"editors": "https://api.twitch.tv/kraken/channels/official_don_gaming/editors",
"videos": "https://api.twitch.tv/kraken/channels/official_don_gaming/videos",
"teams": "https://api.twitch.tv/kraken/channels/official_don_gaming/teams"
},
"background": null,
"banner": null,
"broadcaster_language": "en",
"display_name": "Official_DoN_Gaming",
"game": "Grand Theft Auto V",
"logo": "http://static-cdn.jtvnw.net/jtv_user_pictures/official_don_gaming-profile_image-bbad92a4240c21b3-300x300.png",
"mature": true,
"status": "[GIVEAWAY] $10 Million Challenge & RACES- w/ SUBS n viewers - SUB GOAL 0/5",
"partner": true,
"url": "http://www.twitch.tv/official_don_gaming",
"video_banner": "http://static-cdn.jtvnw.net/jtv_user_pictures/official_don_gaming-channel_offline_image-0302a62c10304fb1-640x360.png",
"_id": 62679916,
"name": "official_don_gaming",
"created_at": "2014-05-16T10:58:17Z",
"updated_at": "2015-03-26T15:16:24Z",
"delay": 0,
"followers": 30943,
"profile_banner": "http://static-cdn.jtvnw.net/jtv_user_pictures/official_don_gaming-profile_banner-2b68918de5679c47-480.png",
"profile_banner_background_color": "#000000",
"views": 162014,
"language": "en"
}
这就是我有时得到的(并不总是发生在相同的频道,它只是随机的)
"channel": {
"_id": 62679916,
"name": "official_don_gaming",
"created_at": "2014-05-16T10:58:17Z",
"updated_at": "2015-03-26T15:16:24Z",
"_links": {
"self": "https://api.twitch.tv/kraken/users/official_don_gaming"
},
"display_name": "Official_DoN_Gaming",
"logo": "http://static-cdn.jtvnw.net/jtv_user_pictures/official_don_gaming-profile_image-bbad92a4240c21b3-300x300.png",
"bio": "Official DoN Gaming started as a Pro Battlefield team, but i have now switched it over to full time streaming and hope to bring you as many new games as possible.",
"type": "user"
}
正如您所看到的,它似乎是转到 / users / 网址而不是 / channels / 网址。关于为什么会发生这种情况的一些见解将不胜感激。