$lien = 'https://demo-api.ig.com/gateway/deal/session';
$path_cookie = __DIR__.'https://a2a3f5h6.rocketcdn.me/cookiesIGtest.txt';
if (!file_exists($path_cookie )) touch($path_cookie);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $lien);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 200);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'userAgentMozilla');
curl_setopt($curl, CURLOPT_POSTFIELDS,'{
"identifier": "myid",
"password": "mypass"
} ');
// $path_cookie = fopen("cookiesIGtest.txt", 'w');
curl_setopt($curl, CURLOPT_COOKIEJAR , $path_cookie);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json',
'VERSION: 2',
'X-IG-API-KEY: 3.........4'
));
curl_setopt($curl, CURLOPT_VERBOSE, true);
$verbose = fopen('request.txt', 'w');
curl_setopt($curl, CURLOPT_STDERR, $verbose);
if(!curl_exec($curl)){
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
else{
$response = curl_exec($curl);
}
curl_close($curl);
$result = json_decode($response, true);
echo '<pre>';
var_dump($result);
echo'</pre>';