<?php
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://www.arcgis.com/sharing/rest/oauth2/token/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "f=json&client_id=i5SFWHVCaYcraPrX&client_secret=36552fbd9a3b4097be4f7cb217bc66b7&grant_type=client_credentials&expiration=60");

$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$token = json_decode($result, true)["access_token"];

/*$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://tiles.arcgis.com/tiles/W6g8dmWX0ILAHcNd/arcgis/rest/services/GenericModel1029/SceneServer');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "f=json&token=".$token."&studyAreas=[{'geometry':{'x':-117.1956,'y':34.0572}}]");

$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);*/
echo $token;
//echo $result;

//curl -X POST -d "f=json" -d "client_id=i5SFWHVCaYcraPrX" -d "client_secret=36552fbd9a3b4097be4f7cb217bc66b7" -d "grant_type=client_credentials" https://www.arcgis.com/sharing/rest/oauth2/token/
//curl -X POST -d "f=json" -d "token=iIpeVkKD54CbMLrxAumro4HpJG6UP0nuc1eYqfa3GgyEEN946d9DAVXB6lcMts2BZHAYwZq4fU9EiBd0Sosk-ENv8F2J9_GwXmNmVjNyIQMhDGr4Wi7O7A2PxvXcrlmG0qLYijr4XtRCQNAZq4aS1g.." -d "studyAreas=[{'geometry':{'x':-117.1956,'y':34.0572}}]" https://tiles.arcgis.com/tiles/W6g8dmWX0ILAHcNd/arcgis/rest/services/GenericModel1029/SceneServer
?>






