Amit Kanala Amit Kanala - 14 days ago 6
JSON Question

Dropbox Shared link metadata Api call with JSON

I Have execute this curl

curl -X POST https://api.dropboxapi.com/2/sharing/get_shared_link_metadata \
--header 'Authorization: Bearer Cf6jn41fHMAAAAAAAAAArF7MRlp5aBgmKo1_JLu7nZ9aX-GRijxMNNcUZwLhwF75' \
--header 'Content-Type: application/json' \
--data '{"url":"https://www.dropbox.com/sh/2su0491a5c6fvxm/AAAzUwxmVDcgR7NbweCDC0IWa?dl=0"}'


My CURL code

$curl = curl_init();
curl_setopt_array( $curl,
array( CURLOPT_CUSTOMREQUEST => 'POST'
, CURLOPT_URL => 'https://api.dropboxapi.com/2/sharing/get_shared_link_metadata'
, CURLOPT_HTTPHEADER => array('Authorization: Bearer Cf6jn41fHMAAAAAAAAAArF7MRlp5aBgmKo1_JLu7nZ9aX-GRijxMNNcUZwLhwF75','Content-Type: application/json','charset=utf-8','dropbox-cors-hack')
, CURLOPT_POSTFIELDS => 'url=https://www.dropbox.com/sh/2su0491a5c6fvxm/AAAzUwxmVDcgR7NbweCDC0IWa?dl=0'
, CURLOPT_RETURNTRANSFER => 1 // means output will be a return value from curl_exec() instead of simply echoed
, CURLOPT_TIMEOUT => 15 // max seconds to wait
, CURLOPT_FOLLOWLOCATION => 0 // don't follow any Location headers, use only the CURLOPT_URL, this is for security
, CURLOPT_FAILONERROR => 0 // do not fail verbosely fi the http_code is an error, this is for security
, CURLOPT_SSL_VERIFYPEER => 1 // do verify the SSL of CURLOPT_URL, this is for security
, CURLOPT_VERBOSE => 0 // don't output verbosely to stderr, this is for security


) );

$response = curl_exec($curl);
curl_close($curl);
echo($response.'<br/>');


Generate This error now

Error in call to API function "sharing/get_shared_link_metadata": request body: could not decode input as JSON


But I want this Response , not getting this response now

{
".tag": "folder",
"url": "https://www.dropbox.com/sh/2su0491a5c6fvxm/AAAzUwxmVDcgR7NbweCDC0IWa?dl=0",
"id": "id:-t9CsOKEi_AAAAAAAAAAIA",
"name": "982sw3rdst",
"path_lower": "/982sw3rdst",
"link_permissions": {
"resolved_visibility": {
".tag": "public"
},
"requested_visibility": {
".tag": "public"
},
"can_revoke": true
}
}


Please check this url just information

https://dropbox.github.io/dropbox-api-v2-explorer/#sharing_get_shared_link_metadata

Answer

Try this code

$curl = curl_init();
$data = array("url" => "https://www.dropbox.com/sh/2su0491a5c6fvxm/AAAzUwxmVDcgR7NbweCDC0IWa?dl=0");
$data_string = json_encode($data);
curl_setopt_array( $curl,
    array( CURLOPT_CUSTOMREQUEST => 'POST'
    , CURLOPT_URL => 'https://api.dropboxapi.com/2/sharing/get_shared_link_metadata'
    , CURLOPT_HTTPHEADER => array('Authorization: Bearer Cf6jn41fHMAAAAAAAAAArF7MRlp5aBgmKo1_JLu7nZ9aX-GRijxMNNcUZwLhwF75','Content-Type: application/json')
    , CURLOPT_POSTFIELDS => $data_string
    ) );

$response = curl_exec($curl);
curl_close($curl);