Skip to content

Instantly share code, notes, and snippets.

@jayshields
Created November 24, 2015 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayshields/fd1afc2c522195457a23 to your computer and use it in GitHub Desktop.
Save jayshields/fd1afc2c522195457a23 to your computer and use it in GitHub Desktop.
Dropbox API output images from directory
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.dropboxapi.com/2/files/list_folder');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer MY_DROPBOX_ACCESS_KEY',
'Content-Type: application/json',
'Accept: application/json'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('path' => '')));
$result = curl_exec($ch);
curl_close($ch);
unset($ch);
$result_arr = json_decode($result);
foreach($result_arr->entries as $r) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.dropboxapi.com/2/sharing/create_shared_link');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer MY_DROPBOX_ACCESS_KEY',
'Content-Type: application/json',
'Accept: application/json'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('path' => $r->path_lower)));
$result = curl_exec($ch);
curl_close($ch);
unset($ch);
$image_data = json_decode($result);
echo '<img src="'.$image_data->url.'&raw=1" />';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment