Created
November 24, 2015 13:05
-
-
Save jayshields/fd1afc2c522195457a23 to your computer and use it in GitHub Desktop.
Dropbox API output images from directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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