You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
6.9 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

[10:43] GUILLIN David
SPACEX:
[10:43] GUILLIN David
$ch =curl_init('https://api.spacexdata.com/v3/launches/60');
// Permet de prendre la data
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
// Initialise le header
curl_setopt($ch,CURLOPT_HEADER,0);
// Execute en json
$response_json =curl_exec($ch);
// decode le json en tableau
$response_php =json_decode($response_json);
print_r($response_php);
curl_close($ch);
[10:43] MASSÉ David
IMDB :
<?php
header("content-type: text/plain;charset=utf-8");
$x_rapidapi_key = "6ab6142a4fmsh81bced26e343a0cp1dd24cjsn97139b9afab0";
$x_rapidapi_host = "imdb8.p.rapidapi.com";
$api_url ="https://imdb8.p.rapidapi.com/";
$rapidapi_pattern = "title/find?q=%tofind%";
$rapidapi_request = str_replace(
"%tofind%", urlencode("Avengers Endgame"),
$rapidapi_pattern);
echo"\n".$api_url.$rapidapi_request."\n";
$curl = curl_init($api_url.$rapidapi_request);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_HTTPHEADER, Array(
"x-rapidapi-host: $x_rapidapi_host",
"x-rapidapi-key: $x_rapidapi_key")
);
$reponse_json = curl_exec($curl);
$reponse_php = json_decode($reponse_json);
print_r($reponse_php);
curl_close($curl);
[11:07] BESSON Mathieu
<?php
header("Content-type: text/plain;charset=utf-8");
define("API_KEY","0c659161aae51ff51a6c0c41c8a591b5");
define("API_HOST","v3.football.api-sports.io");
// $url = "https://reqbin.com/echo/get/json";
$url ="https://v3.football.api-sports.io/leagues?name=Premier League";
$curl =curl_init($url);
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
$headers =array(
"x-rapidapi-host: ".API_HOST,
"x-rapidapi-key: ".API_KEY,
"Content-Type: application/json"
);
curl_setopt($curl,CURLOPT_HTTPHEADER,$headers);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
$resp =curl_exec($curl);
curl_close($curl);
var_dump($resp);
[11:08] GERARD Malo
Spotify :
<?php
header("Content-type: text/plain;charset=utf-8");
$client_id = '006eb744736e4ee78eabf5e688b44c47';
$client_secret = 'f552504f0d9a40dbb1c29e38f4b91e5d';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, 'https://accounts.spotify.com/api/token' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials' );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic '.base64_encode($client_id.':'.$client_secret)));
$result=curl_exec($ch);
if(curl_errno($ch)){
$errstr = curl_errno($ch).": ".curl_error($ch);
}
curl_close ($ch);
if(isset($errstr)){
echo$errstr;
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($curl, CURLOPT_POST, 1);
// curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
$data['grant_type'] = 'client_credentials';
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_URL, 'https://api.spotify.com/v1/tracks?ids=11dFghVXANMlKmJXsNCbNl');
$token = json_decode($result);
$headers = array(
'Authorization' => 'Bearer '.$token->access_token,
'Content-Type' => 'application/json',
'Accept' => 'application/json'
);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response_json = curl_exec($curl);
if(curl_errno($curl)){
$errstr = curl_errno($curl).": ".curl_error($curl);
}
curl_close ($curl);
if(isset($errstr)){
echo$errstr;
}
print_r($response_json);
//$response_php = json_decode($response_json);
//print_r($response_php->features[0]->geometry->coordinates);
curl_close($curl);
[11:41] GUILLIN David
Cors
First enable mod_headers on your server, then you can use header directive in both Apache conf and .htaccess.
enable mod_headers
a2enmod headers
configure header in .htaccess file
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
TEAM LOL
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
$apiUrl = "localhost:8080/";
$pattern = "api/lastmatch?name=".urlencode($_GET["name"]);
$curl = curl_init($apiUrl.$pattern);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response_json = curl_exec($curl);
$response_php = json_decode($response_json);
foreach ($response_php as $value) {
print_r(
'<br>'.'Nom : '.$value->name.
'<br>'.'Niveau : '.$value->level.
'<br>'.'Champion : '.$value->champion.
'<br>'.'Kill / Death / Assist : '.$value->kda.
'<br>'.'Résultat du match : '.$value->resultat.
'<br>'.'---------------------------------------'
);
}
curl_close($curl);
?>
</body>
</html>
TEAM POKEMON ::
<?php
header("Content-type: text/plain;charset=utf-8");
// afficher les types de pokemon
$api_url = "https://pokeapi.co/api/v2/type/";
echo "\n".$api_url;
$curl = curl_init($api_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//true pour retourner le transfert en tant que chaîne de caractères de la valeur retournée par curl_exec() au lieu de l'afficher directement.
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // désactive les demandes de certificats SSL lors d'appel
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // idem
$response_json = curl_exec($curl);
// gérer les erreurs
if (curl_errno($curl)) {
$error_msg = curl_error($curl);
}
curl_close($curl);
if (isset($error_msg)) {
var_dump($error_msg);
exit;
}
print_r($response_json);
curl_close($curl);
//////////////////////////////////////
// afficher les pokemon du type 3
$api_url2 = "https://pokeapi.co/api/v2/type/3";
$curl2 = curl_init($api_url2);
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl2, CURLOPT_SSL_VERIFYHOST, 0); // désactive les demandes de certificats SSL lors d'appel
curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, 0); // idem
$response_json = curl_exec($curl2);
// gérer les erreurs
if (curl_errno($curl2)) {
$error_msg = curl_error($curl2);
}
curl_close($curl2);
if (isset($error_msg)) {
var_dump($error_msg);
exit;
}
$response_php = json_decode($response_json);
print_r($response_php-> pokemon);
curl_close($curl2);