BLOG

The newest information presented by iSports API

How to get Lineups - Football API sample code

Posted on July 05, 2020

Share the sample code using the interface call of iSports Api Sports Data www.isportsapi.com. This API endpoint returns the lineups of the specified match. If some matches have no lineups or no specific formations, then the player position will return 0.

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/lineups?api_key=<YOUR_API_KEY>&matchId=ID";

    // 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": "1720293",
      "homeFormation": "",
      "awayFormation": "",
      "homeLineup": [
        {
          "playerId": "89854",
          "name": "Daniel Gimenez Hernandez",
          "number": 1,
          "position": 0
        },
        {
          "playerId": "66799",
          "name": "Alejandro Bergantinos Garcia, Alex",
          "number": 4,
          "position": 0
        }
      ],
      "awayLineup": [
        {
          "playerId": "133085",
          "name": "Munir Mohand Mohamedi",
          "number": 1,
          "position": 0
        },
        {
          "playerId": "28881",
          "name": "Adrian Gonzalez Morales",
          "number": 8,
          "position": 0
        }
      ],
      "homeBackup": [
        {
          "playerId": "60320",
          "name": "Eneko Boveda",
          "number": 24,
          "position": 0
        },
        {
          "playerId": "140672",
          "name": "Diego Caballo",
          "number": 17,
          "position": 0
        }
      ],
      "awayBackup": [
        {
          "playerId": "167738",
          "name": "Hicham Boussefiane",
          "number": 31,
          "position": 0
        },
        {
          "playerId": "143534",
          "name": "Diego Gonzalez Polanco",
          "number": 3,
          "position": 0
        }
      ]
    }
  ]
}
Introduction
Related Plans
Request
Response
Example Request
Example Response

Contact


Top

Products

Contact