I hope you can help. I am trying to get a URL from DropBox using cURL. I am able to upload the file with cURL and retrieve the uploaded file. I have taken the uploaded ID and passed it into the Headers and I get back NULL after I decoded JSON. I am not sure what I am missing. I have attached the code below.
$cheaders = array('Authorization: Bearer xxx',
'Content-Type: application/octet-stream',
"Dropbox-API-Arg: {\"path\": \"/Homework/math/Prime_Numbers.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": true}");
//var_dump($cheaders);
$ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $cheaders);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo '<pre>';
var_dump(json_decode($response));
$obj =json_decode($response);
print str_replace('id:','',$obj->{'id'});
echo '</pre>';
fclose($fp);
$File_ID = $obj->{'id'};
$cheaders2 = array('Authorization: Bearer xxx',
"Content-Type: application/json" ,
"{\"file\": \"id:zFe2SHxKbHEAAAAAAAJc-g\",\"actions\": []}"
);
$ch2 = curl_init('https://api.dropboxapi.com/2/sharing/get_file_metadata');
curl_setopt($ch2, CURLOPT_HTTPHEADER, $cheaders2);
curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
$response2 = curl_exec($ch2);
var_dump(json_decode($response2));