-
-
Save nabaasa/5f4f641335382164d38431050b0b9905 to your computer and use it in GitHub Desktop.
Lufthansa REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Lufthansa REST API with OAuth | |
// exchange client_id and client_secret for the token | |
$post = [ | |
'client_id' => 'Your client Id', | |
'client_secret' => 'Your client secret', | |
'grant_type' => 'client_credentials', | |
]; | |
$ch = curl_init(); | |
// exchange credentials for token | |
$url = "https://api.lufthansa.com/v1/oauth/token"; | |
curl_setopt($ch, CURLOPT_URL,$url); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$output = curl_exec ($ch); | |
curl_close ($ch); | |
$tok = json_decode($output, true); | |
// place the token in HTTP header to get list of airports | |
$ch = curl_init(); | |
// end-point for list of airlines | |
curl_setopt($ch, CURLOPT_URL,"https://api.lufthansa.com/v1/references/airlines?limit=20&offset=3"); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$headers = [ | |
'Accept: application/json', | |
'Authorization: Bearer '.$tok["access_token"], | |
'X-Originating-Ip: '.$_SERVER['SERVER_ADDR'] | |
]; | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
$server_output = curl_exec ($ch); | |
curl_close ($ch); | |
print $server_output ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Helpful. Thank you very much.