Bonjour,

J'ai quelques difficultés à récupérer les informations venant d'un service REST (oauth2), le token et bien récupéré mais impossible je ne comprend pas trop comment le placer dans le header pour afficher les données de l'api.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
 
 
$client_id = 'xxx';
$client_secret = 'xxxxxxx';
 
$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://xxxxx/token");// On récupére le token
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(
     'client_id' => $client_id,
     'client_secret' => $client_secret,
     'grant_type' => 'client_credentials'
));
 
     $json = json_decode(curl_exec($ch));
     curl_close($ch);
 // var_dump ($json->access_token);
    $token = $json->access_token;
 
echo $token;
 
 
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, "https://xxx/cards");
 
$header = array(
   'Accept: application/json',
   'Content-Type: application/x-www-form-urlencoded',
   'Authorization: Bearer ' .$token
   );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
 
       $result = curl_exec($ch);
 
        json_decode($result);
	    var_dump ($result);
	    curl_close($ch);
Merci à tous