PHP
Most popular language is placed most popular on top. There are two ways I'll show you: native and by using Guzzle library. First let's see how to get all matches of the 22th matchday of the Premiere League by firing an authenticated request:<?php
$uri = 'http://api.football-data.org/v2/competitions/PL/matches/?matchday=22';
$reqPrefs['http']['method'] = 'GET';
$reqPrefs['http']['header'] = 'X-Auth-Token: YOUR_API_TOKEN';
$stream_context = stream_context_create($reqPrefs);
$response = file_get_contents($uri, false, $stream_context);
$matches = json_decode($response);
?>
Though I like the puristic nature of this code, I think using a sophisticated library is way more convient. Assuming you have installed Guzzle via composer you can assemble an authenticated request like so:
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();
$uri = 'http://api.football-data.org/v2/competitions/BL1/standings';
$header = array('headers' => array('X-Auth-Token' => 'YOUR_API_TOKEN'));
$response = $client->get($uri, $header);
$json = $response->json();
?>
Python
Firing a small authenticated request using Python 3 looks like so:import http.client
import json
connection = http.client.HTTPConnection('api.football-data.org')
headers = { 'X-Auth-Token': 'YOUR_API_TOKEN' }
connection.request('GET', '/v2/competitions/DED', None, headers )
response = json.loads(connection.getresponse().read().decode())
print (response)
R
R is a programming language specifically for statistical purposes. that code sample:install.packages("httr")
library("httr")
matches = GET("https://api.football-data.org/v2/competitions",
add_headers("X-Auth-Token"="YOUR_TOKEN")
)
content(a)