BLOG

The newest information presented by iSports API

How to get Events - Football API sample code

Posted on June 28, 2020

Share the sample code using the interface call of iSports Api Sports Data www.isportsapi.com. This API endpoint returns instant event of football matches for the current day( GMT +0 00:00-23:59 ), such as goals, yellow and red cards, substitution, etc.

The event will be added, modified or deleted. Each eventId stands for an event, which will only be added or deleted. You need to synchronize the data with eventId.

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class SportDemo {
  public static void main(String[] args) {
    // Set url parameter
    String url = "http://api.isportsapi.com/sport/football/events?api_key=<YOUR_API_KEY>";

    // Call iSport Api to get data in json format
    String charset = "UTF-8";
    String jsonResult = get(url, charset);

        System.out.println(jsonResult);
  }

  /**
   * @param url
   * @param charset
   * @return return json string
   */
  public static String get(String url, String charset) {
    BufferedReader reader = null;
    String result = null;
    StringBuffer sbf = new StringBuffer();
    String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
    try {
      URL newUrl = new URL(url);
      HttpURLConnection connection = (HttpURLConnection)newUrl.openConnection();
      connection.setRequestMethod("GET");
      connection.setReadTimeout(30000);
      connection.setConnectTimeout(30000);
      connection.setRequestProperty("User-agent", userAgent);
      connection.connect();
      InputStream is = connection.getInputStream();
      reader = new BufferedReader(new InputStreamReader(is, charset));
      String strRead = null;
      while ((strRead = reader.readLine()) != null) {
        sbf.append(strRead);
        sbf.append("\r\n");
      }
      reader.close();
      result = sbf.toString();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return result;
  }
}

The football API returns the data as follows:

{
  "code": 0,
  "message": "success",
  "data": [
    {
      "matchId": "1676841",
      "events": [
        {
          "eventId": "6600089",
          "minute": "45",
          "type": 3,
          "playerId": "83800",
          "playerName": "Cicero Dos Santos Bezerra,Didira",
          "assistPlayerId": "",
          "homeEvent": true
        },
        {
          "eventId": "6600090",
          "minute": "55",
          "type": 3,
          "playerId": "130189",
          "playerName": "Jonathan David Gomez",
          "assistPlayerId": "",
          "homeEvent": true
        },
        {
          "eventId": "6600091",
          "minute": "65",
          "type": 1,
          "playerId": "110560",
          "playerName": "Victor Vinicius Coelho Santos (Assist:Everton Augusto de Barros Ribeiro)",
          "assistPlayerId": "",
          "homeEvent": false
        },
        {
          "eventId": "6600092",
          "minute": "71",
          "type": 11,
          "playerId": "83236",
          "playerName": "(25)↑(2)↓",
          "assistPlayerId": "",
          "homeEvent": true
        },
        {
          "eventId": "6600093",
          "minute": "77",
          "type": 1,
          "playerId": "117308",
          "playerName": "Gabriel Gabigol",
          "assistPlayerId": "",
          "homeEvent": false
        },
        {
          "eventId": "6600094",
          "minute": "79",
          "type": 11,
          "playerId": "166976",
          "playerName": "(99)↑(9)↓",
          "assistPlayerId": "",
          "homeEvent": true
        },
        {
          "eventId": "6600095",
          "minute": "80",
          "type": 3,
          "playerId": "121976",
          "playerName": "Leandro Rosa Souza",
          "assistPlayerId": "",
          "homeEvent": true
        },
        {
          "eventId": "6600096",
          "minute": "83",
          "type": 11,
          "playerId": "161317",
          "playerName": "(29)↑(27)↓",
          "assistPlayerId": "",
          "homeEvent": false
        },
        {
          "eventId": "6600097",
          "minute": "84",
          "type": 11,
          "playerId": "155916",
          "playerName": "(23)↑(16)↓",
          "assistPlayerId": "",
          "homeEvent": true
        },
        {
          "eventId": "6600098",
          "minute": "87",
          "type": 3,
          "playerId": "117308",
          "playerName": "Gabriel Gabigol",
          "assistPlayerId": "",
          "homeEvent": false
        },
        {
          "eventId": "6600099",
          "minute": "88",
          "type": 11,
          "playerId": "71744",
          "playerName": "(28)↑(9)↓",
          "assistPlayerId": "",
          "homeEvent": false
        },
        {
          "eventId": "6600100",
          "minute": "90",
          "type": 11,
          "playerId": "176510",
          "playerName": "(32)↑(2)↓",
          "assistPlayerId": "",
          "homeEvent": false
        }
      ]
    }
  ]
}

Contact