A Personalized Twitch Resources Recommendation Engine 2

Wed, Jun 16, 2021 One-minute read

twitch tutorial

Backend Code Structure

We’re going to implement all the functionalities in the following diagram.

image

diagram

Client

  • GameServlet: doGet
    • TwitchClient:topGame
    • TwitchClient:searchGame
  • TwitchClient:searTwitch Twitch

get token form Twitch

  1. register in dev.twitch, get Client_id and Client_secret ready
  2. open postman and the Twitch token generate request to get the access token for calling Twitch APIs
{
    "access_token": "ddx06i6thux3yl5v1jnugx9mqrk8kt",
    "expires_in": 5670001,
    "token_type": "bearer"
}
  1. test,get top games

postman, set up the {{ACCESS_TOKEN}} and {{CLIENT_ID}}

https://api.twitch.tv/helix/games/top

  1. success
{
    "data": [
        {
            "id": "509658",
            "name": "Just Chatting",
            "box_art_url": "https://static-cdn.jtvnw.net/ttv-boxart/509658-{width}x{height}.jpg",
            "igdb_id": ""
        },
        {....
        }
}

Now the token is working.

Connect to Twitch API with Java

1. RESTful Java client with Apache HttpClient

CloseableHttpClient httpclient = HttpClients.createDefault();

    ResponseHandler<String> responseHandler = response -> {
        int responseCode = response.getStatusLine().getStatusCode();
    
        HttpEntity entity = response.getEntity();

2. Update Game Class to Match Twitch Response

public class Game{

}

3. Create a new package for the external APIs

get top games

  • TwitchClient:topGame
  • TwitchClient:searchGame
  • TwitchClient:searTwitch

test

https://api.twitch.tv/helix/games/top

from the api.twitch to localhost:8080,

http://localhost:8080/jupiter/game?game_name=Starcraft II

httpclient


Client

  • SerchServlet: doGet
    • TwitchClient:searchItems
      • TwitchClient:searchByType
        • TwitchClient:searchStream
        • TwitchClient:searchVideo
        • TwitchClient:searchClips
  • TwitchClient:searTwitch Twitch

1. Add Item Class to Match Twitch Response

ItemType: STREAM, VIDEO, CLIP

2. Add method in TwitchClient

goals

https://api.twitch.tv/helix/videos?game_id=12000 https://api.twitch.tv/helix/clips?game_id=12000

http://localhost:8080/jupiter/search?game_id=100000