Hi, I would like to request top game data for my test application https://dev.twitch.tv/docs/v5/reference/games, but I have difficulties at the data request stage. Tell me what I should correct please
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val o =
createRequest("https://api.twitch.tv/kraken/games/top")
.map { Gson().fromJson(it, Feed::class.java) }
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
}
}
class Feed(
val items: ArrayList<FeedItem>
)
class FeedItem(
val name: String, val channels: String, val viewers: String, val logo: ImageView
)
//CreateRequest func in utils:
fun createRequest (url:String) = Observable.create<String> {
val urlConnection = URL (url).openConnection() as HttpURLConnection
urlConnection.requestMethod = "GET"
urlConnection.setRequestProperty("Client-ID",
"0mbng65k95r72we0j1ii1uf02cssrs")
try {
urlConnection.connect()
if(urlConnection.responseCode != HttpURLConnection.HTTP_OK)
it.onError(RuntimeException(urlConnection.responseMessage))
else {
val str = urlConnection.inputStream.bufferedReader().readText()
it.onNext(str)
}
} finally {
urlConnection.disconnect()
}
}
You don’t appear to be sending the Accept: application/vnd.twitchtv.v5+json header, so are likely getting a 410 response because you’re sending a request to a version of the API (v3) that doesn’t exist any more.