├── .gitignore ├── Example.php ├── LICENSE ├── README.md ├── composer.json ├── composer.lock └── sdk ├── Dropbox.php └── Dropbox ├── Auth.php ├── FileProperties.php ├── FileRequests.php ├── Files.php ├── Misc.php ├── Paper.php ├── Sharing.php └── Users.php /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | /vendor 3 | /vendor/* -------------------------------------------------------------------------------- /Example.php: -------------------------------------------------------------------------------- 1 | files->download('/target/file.txt', '/path-to-download-to/downloadedfile.txt'); 10 | 11 | // Upload a file, overwriting if the file already exists in Dropbox 12 | $dropbox->files->upload('/target/file.txt', '/path-to-upload-from/uploadthisfile.txt', "overwrite"); 13 | 14 | // List all the files in a folder 15 | $dropbox->files->list_folder('/example_path'); 16 | 17 | /***Documentation will be added/updated in the future***/ 18 | ?> -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Luke Baird 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dropbox-v2-PHP-SDK 2 | PHP SDK for Dropbox built with the v2 API 3 | 4 | *Last update: 2/23/2018* 5 | 6 | ## Installation 7 | - Run `composer require lukebaird/dropbox-v2-php-sdk` in your project root 8 | 9 | ### Additional info 10 | - [Packagist.org link](https://packagist.org/packages/lukebaird/dropbox-v2-php-sdk) 11 | - Latest version: `v1.1.6` 12 | 13 | ## Documentation 14 | - Documentation will be improved in the future. Check out [Example.php](Example.php) for basic usage. 15 | - [Dropbox API documentation](https://www.dropbox.com/developers/documentation/http/documentation) 16 | - You can look in the appropriate file to see usage. 17 | 18 | ### Version 1.1.7 19 | - Added option to `files->upload()` and `files->download()` to upload/download raw data respectively. 20 | - Please see `sdk/Dropbox/Files.php` for usage. 21 | ---------------------- 22 | 23 | **Bolded** items will not be implemented. 24 | 25 | ### auth 26 | - [x] /token/from_oauth1 27 | - [x] /token/revoke 28 | 29 | ### file_properties 30 | - [x] /properties/add 31 | - [x] /properties/overwrite 32 | - [x] /properties/remove 33 | - [x] /properties/search 34 | - [x] /properties/update 35 | - [x] /templates/add_for_user 36 | - [x] /templates/get_for_user 37 | - [x] /templates/list_for_user 38 | - [x] /templates/update_for_user 39 | 40 | ### file_requests 41 | - [x] /create 42 | - [x] /get 43 | - [x] /list 44 | - [x] /update 45 | 46 | ### files 47 | - [ ] **/alpha/get_metadata** *PREVIEW* 48 | - [ ] **/alpha/upload** *PREVIEW* 49 | - [x] /copy *DEPRECATED BY /copy_v2* 50 | - [x] /copy_batch 51 | - [x] /copy_batch/check 52 | - [x] /copy_reference/get 53 | - [x] /copy_reference/save 54 | - [x] /copy_v2 55 | - [x] /create_folder *DEPRECATED BY /create_folder_v2* 56 | - [x] /create_folder_v2 57 | - [x] /delete *DEPRECATED BY /delete_v2* 58 | - [x] /delete_batch 59 | - [x] /delete_batch/check 60 | - [x] /delete_v2 61 | - [x] /download 62 | - [x] /get_metadata 63 | - [x] /get_preview 64 | - [x] /get_temporary_link 65 | - [x] /get_thumbnail 66 | - [x] /list_folder 67 | - [x] /list_folder/continue 68 | - [x] /list_folder/get_latest_cursor 69 | - [x] /list_folder/longpoll 70 | - [x] /list_revisions 71 | - [x] /move *DEPRECATED BY /move_v2* 72 | - [x] /move_batch 73 | - [x] /move_batch/check 74 | - [x] /move_v2 75 | - [x] /permanently_delete 76 | - [ ] **/properties/add** *PREVIEW* 77 | - [ ] **/properties/overwrite** *PREVIEW* 78 | - [ ] **/properties/remove** *PREVIEW* 79 | - [ ] **/properties/template/get** *PREVIEW* 80 | - [ ] **/properties/update** *PREVIEW* 81 | - [x] /restore 82 | - [x] /save_url 83 | - [x] /save_url/check_job_status 84 | - [x] /search 85 | - [x] /upload 86 | - [x] /upload_session/append *DEPRECATED BY /upload_session/append_v2* 87 | - [x] /upload_session/append_v2 88 | - [x] /upload_session/finish 89 | - [x] /upload_session/finish_batch 90 | - [x] /upload_session/finish_batch/check 91 | - [x] /upload_session/start 92 | 93 | ### paper 94 | - [x] /docs/archive 95 | - [x] /docs/create 96 | - [x] /docs/download 97 | - [x] /docs/folder_users/list 98 | - [x] /docs/folder_users/list/continue 99 | - [x] /docs/get_folder_info 100 | - [x] /docs/list 101 | - [x] /docs/list/continue 102 | - [x] /docs/permanently_delete 103 | - [x] /docs/sharing_policy/get 104 | - [x] /docs/sharing_policy/set 105 | - [x] /docs/users/add 106 | - [x] /docs/users/list 107 | - [x] /docs/users/list/continue 108 | - [x] /docs/users/remove 109 | 110 | ### sharing 111 | - [x] /add_file_member 112 | - [x] /add_folder_member 113 | - [x] /change_file_member_access *DEPRECATED BY /update_file_member* 114 | - [x] /check_job_status 115 | - [x] /check_remove_member_job_status 116 | - [x] /check_share_job_status 117 | - [x] /create_shared_link *DEPRECATED BY /create_shared_link_with_settings* 118 | - [x] /create_shared_link_with_settings 119 | - [x] /get_file_metadata 120 | - [x] /get_file_metadata/batch 121 | - [x] /get_folder_metadata 122 | - [x] /get_shared_link_file 123 | - [x] /get_shared_link_metadata 124 | - [x] /get_shared_links *DEPRECATED BY /list_shared_links* 125 | - [x] /list_file_members 126 | - [x] /list_file_members/batch 127 | - [x] /list_file_members/continue 128 | - [x] /list_folder_members 129 | - [x] /list_folder_members/continue 130 | - [x] /list_folders 131 | - [x] /list_folders/continue 132 | - [x] /list_mountable_folders 133 | - [x] /list_mountable_folders/continue 134 | - [x] /list_received_files 135 | - [x] /list_received_files/continue 136 | - [x] /list_shared_links 137 | - [x] /modify_shared_link_settings 138 | - [x] /mount_folder 139 | - [x] /relinquish_file_membership 140 | - [x] /relinquish_folder_membership 141 | - [x] /remove_file_member *DEPRECATED BY /remove_file_member_2* 142 | - [x] /remove_file_member_2 143 | - [x] /remove_folder_member 144 | - [x] /revoke_shared_link 145 | - [x] /share_folder 146 | - [x] /transfer_folder 147 | - [x] /unmount_folder 148 | - [x] /unshare_file 149 | - [x] /unshare_folder 150 | - [x] /update_file_member 151 | - [x] /update_folder_member 152 | - [x] /update_folder_policy 153 | 154 | ### users 155 | - [x] /get_account 156 | - [x] /get_account_batch 157 | - [x] /get_current_account 158 | - [x] /get_space_usage 159 | ------------------ 160 | 161 | ## Additional Functions 162 | 163 | ### `Dropbox/Files->getThumbnailSize($size)` 164 | Converts standard thumbnail sizes into pixel values usable by Dropbox functions, i.e. `'thumb' => 'w32h32'` 165 | 166 | ## Troubleshooting 167 | 168 | ### Local Machine SSL Certificate Issues 169 | Dropbox requires that you have a valid SSL certificate. If you are facing an issue where the SDK is always returning `null` or `false`, this could be the issue. Try following the solution to [this StackOverflow question](https://stackoverflow.com/questions/28858351/php-ssl-certificate-error-unable-to-get-local-issuer-certificate). -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lukebaird/dropbox-v2-php-sdk", 3 | "license": "MIT", 4 | "description": "A Dropbox SDK to work with the v2 API", 5 | "require": { 6 | "php": "^5.3.3 || ^7.0" 7 | }, 8 | "autoload": { 9 | "psr-4" : { 10 | "Dropbox\\": "sdk/" 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "12f60857477f15d9f92301076a7c0782", 8 | "packages": [], 9 | "packages-dev": [], 10 | "aliases": [], 11 | "minimum-stability": "stable", 12 | "stability-flags": [], 13 | "prefer-stable": false, 14 | "prefer-lowest": false, 15 | "platform": { 16 | "php": "^5.3.3 || ^7.0" 17 | }, 18 | "platform-dev": [] 19 | } 20 | -------------------------------------------------------------------------------- /sdk/Dropbox.php: -------------------------------------------------------------------------------- 1 | auth = new Auth(); 29 | $this->files = new Files(); 30 | $this->file_properties = new FileProperties(); 31 | $this->file_requests = new FileRequests(); 32 | $this->paper = new Paper(); 33 | $this->misc = new Misc(); 34 | $this->sharing = new Sharing(); 35 | $this->users = new Users(); 36 | } 37 | 38 | /* 39 | * Main function for handling post requests. 40 | */ 41 | public static function postRequest($endpoint, $headers, $data, $json = TRUE) { 42 | $ch = curl_init($endpoint); 43 | array_push($headers, "Authorization: Bearer " . self::$token); 44 | curl_setopt($ch, CURLOPT_POST, TRUE); 45 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 46 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 47 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 48 | $r = curl_exec($ch); 49 | curl_close($ch); 50 | 51 | if ($json) 52 | return json_decode($r, true); 53 | else 54 | return $r; 55 | } 56 | 57 | /* 58 | * Special case function for handling the from_oauth1 request 59 | */ 60 | public static function oauth1Request($endpoint, $data, $app_key, $app_secret) { 61 | $ch = curl_init($endpoint); 62 | $headers = array("Content-Type: application/json"); 63 | curl_setopt($ch, CURLOPT_POST, TRUE); 64 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 65 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 66 | curl_setopt($ch, CURLOPT_USERPWD, "$app_key:$app_secret"); 67 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 68 | $r = curl_exec($ch); 69 | curl_close($ch); 70 | return json_decode($r, true); 71 | } 72 | 73 | /* 74 | * Updates the access token. 75 | */ 76 | public function updateAccessToken($accesstoken) { 77 | self::$token = $accesstoken; 78 | } 79 | } 80 | 81 | ?> -------------------------------------------------------------------------------- /sdk/Dropbox/Auth.php: -------------------------------------------------------------------------------- 1 | updateAccessToken($token) to update the SDK with your new token 19 | */ 20 | public function from_oauth1($oauth1_token, $oauth1_token_secret, $app_key, $app_secret) { 21 | $endpoint = "https://api.dropboxapi.com/2/token/from_oauth1"; 22 | $postdata = json_encode(array( "oauth1_token" => $oauth1_token, "oauth1_token_secret" => $oauth1_token_secret )); 23 | $returnData = Dropbox::oauth1Request($endpoint, $postdata, $app_key, $app_secret); 24 | if (isset($returnData["error"])) { 25 | return $returnData["error_summary"]; 26 | } 27 | else { 28 | return $returnData["oauth2_token"]; 29 | } 30 | } 31 | 32 | /* 33 | * Revokes an access token 34 | */ 35 | public function revoke() { 36 | $endpoint = "https://api.dropboxapi.com/2/token/revoke"; 37 | $headers = array(); 38 | $postdata = json_encode(array()); 39 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 40 | if (isset($returnData["error"])) { 41 | return $returnData["error_summary"]; 42 | } 43 | else { 44 | return $returnData; 45 | } 46 | } 47 | } 48 | 49 | ?> 50 | -------------------------------------------------------------------------------- /sdk/Dropbox/FileProperties.php: -------------------------------------------------------------------------------- 1 | $path, "property_groups" => $property_groups )); 24 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 25 | if (isset($returnData["error"])) { 26 | return $returnData["error_summary"]; 27 | } 28 | else { 29 | return $returnData; 30 | } 31 | } 32 | 33 | /* 34 | * Overwrite property groups associated with a file 35 | */ 36 | public function overwrite($path, $property_groups) { 37 | $endpoint = "https://api.dropboxapi.com/2/file_properties/properties/overwrite"; 38 | $headers = array( 39 | "Content-Type: application/json" 40 | ); 41 | $postdata = json_encode(array( "path" => $path, "property_groups" => $property_groups )); 42 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 43 | if (isset($returnData["error"])) { 44 | return $returnData["error_summary"]; 45 | } 46 | else { 47 | return $returnData; 48 | } 49 | } 50 | 51 | /* 52 | * Remove the specified property group from the file 53 | */ 54 | public function remove($path, $property_groups) { 55 | $endpoint = "https://api.dropboxapi.com/2/file_properties/properties/remove"; 56 | $headers = array( 57 | "Content-Type: application/json" 58 | ); 59 | $postdata = json_encode(array( "path" => $path, "property_groups" => $property_groups )); 60 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 61 | if (isset($returnData["error"])) { 62 | return $returnData["error_summary"]; 63 | } 64 | else { 65 | return $returnData; 66 | } 67 | } 68 | 69 | /* 70 | * Search across property templates for particular property field values 71 | */ 72 | public function search($queries, $template_filter) { 73 | $endpoint = "https://api.dropboxapi.com/2/file_properties/properties/search"; 74 | $headers = array( 75 | "Content-Type: application/json" 76 | ); 77 | $postdata = json_encode(array( "queries" => $queries, "template_filter" => $template_filter )); 78 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 79 | if (isset($returnData["error"])) { 80 | return $returnData["error_summary"]; 81 | } 82 | else { 83 | return $returnData; 84 | } 85 | } 86 | 87 | /* 88 | * Remove the specified property group from the file 89 | */ 90 | public function update($path, $update_property_groups) { 91 | $endpoint = "https://api.dropboxapi.com/2/file_properties/properties/update"; 92 | $headers = array( 93 | "Content-Type: application/json" 94 | ); 95 | $postdata = json_encode(array( "path" => $path, "update_property_groups" => $update_property_groups )); 96 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 97 | if (isset($returnData["error"])) { 98 | return $returnData["error_summary"]; 99 | } 100 | else { 101 | return $returnData; 102 | } 103 | } 104 | 105 | /* 106 | * Add a template associated with a user. 107 | */ 108 | public function templates_add_for_user($name, $description, $fields) { 109 | $endpoint = "https://api.dropboxapi.com/2/file_properties/templates/add_for_user"; 110 | $headers = array( 111 | "Content-Type: application/json" 112 | ); 113 | $postdata = json_encode(array( "name" => $name, "description" => $description, "fields" => $fields )); 114 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 115 | if (isset($returnData["error"])) { 116 | return $returnData["error_summary"]; 117 | } 118 | else { 119 | return $returnData; 120 | } 121 | } 122 | 123 | /* 124 | * Get the schema for a specified template 125 | */ 126 | public function templates_get_for_user($name, $description, $fields) { 127 | $endpoint = "https://api.dropboxapi.com/2/file_properties/templates/get_for_user"; 128 | $headers = array( 129 | "Content-Type: application/json" 130 | ); 131 | $postdata = json_encode(array( "name" => $name, "description" => $description, "fields" => $fields )); 132 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 133 | if (isset($returnData["error"])) { 134 | return $returnData["error_summary"]; 135 | } 136 | else { 137 | return $returnData; 138 | } 139 | } 140 | 141 | /* 142 | * Get the template identifiers for a team 143 | */ 144 | public function templates_list_for_user() { 145 | $endpoint = "https://api.dropboxapi.com/2/file_properties/templates/list_for_user"; 146 | $headers = array(); 147 | $postdata = json_encode(array()); 148 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 149 | if (isset($returnData["error"])) { 150 | return $returnData["error_summary"]; 151 | } 152 | else { 153 | return $returnData; 154 | } 155 | } 156 | 157 | /* 158 | * Update a template associated with a user 159 | * @param $add_fields: a list of PropertyFieldTemplate with values name, description, and type 160 | */ 161 | public function templates_update_for_user($template_id, $name, $description, $add_fields) { 162 | $endpoint = "https://api.dropboxapi.com/2/file_properties/templates/update_for_user"; 163 | $headers = array( 164 | "Content-Type: application/json" 165 | ); 166 | $postdata = json_encode(array( "template_id" => $template_id, "name" => $name, "description" => $description, "add_fields" => $add_fields )); 167 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 168 | if (isset($returnData["error"])) { 169 | return $returnData["error_summary"]; 170 | } 171 | else { 172 | return $returnData; 173 | } 174 | } 175 | 176 | 177 | // * * ***** **** **** 178 | // ** ** * * * 179 | // * * * * *** * 180 | // * * * * * 181 | // * * ***** **** **** * 182 | 183 | public function __construct() { 184 | } 185 | 186 | } 187 | 188 | ?> -------------------------------------------------------------------------------- /sdk/Dropbox/FileRequests.php: -------------------------------------------------------------------------------- 1 | $title, "destination" => $destination, "deadline" => "$deadline", "open" => $open )); 24 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 25 | if (isset($returnData["error"])) { 26 | return $returnData["error_summary"]; 27 | } 28 | else { 29 | return $returnData; 30 | } 31 | } 32 | 33 | /* 34 | * returns the specified file request 35 | */ 36 | public function get($id) { 37 | $endpoint = "https://api.dropboxapi.com/2/file_requests/get"; 38 | $headers = array( 39 | "Content-Type: application/json" 40 | ); 41 | $postdata = json_encode(array( "id" => $id )); 42 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 43 | if (isset($returnData["error"])) { 44 | return $returnData["error_summary"]; 45 | } 46 | else { 47 | return $returnData; 48 | } 49 | } 50 | 51 | /* 52 | * Returns a list of file requests owned by this user. 53 | */ 54 | public function llist() { 55 | $endpoint = "https://api.dropboxapi.com/2/file_requests/list"; 56 | $headers = array(); 57 | $postdata = json_encode(array()); 58 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 59 | if (isset($returnData["error"])) { 60 | return $returnData["error_summary"]; 61 | } 62 | else { 63 | return $returnData; 64 | } 65 | } 66 | 67 | /* 68 | * Update a file request 69 | * @param $deadline: the deadline for the file request. type UpdateFileRequestDeadline, either .tag: "no_update" or a tag of update with a FileRequestDeadline 70 | */ 71 | public function update($id, $title = "", $destination = "", $deadline = array(".tag" => "no_update"), $open = TRUE) { 72 | $endpoint = "https://api.dropboxapi.com/2/file_requests/create"; 73 | $headers = array( 74 | "Content-Type: application/json" 75 | ); 76 | $postdata = json_encode(array( "id" => $id, "title" => $title, "destination" => $destination, "deadline" => "$deadline", "open" => $open )); 77 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 78 | if (isset($returnData["error"])) { 79 | return $returnData["error_summary"]; 80 | } 81 | else { 82 | return $returnData; 83 | } 84 | } 85 | 86 | 87 | // * * ***** **** **** 88 | // ** ** * * * 89 | // * * * * *** * 90 | // * * * * * 91 | // * * ***** **** **** * 92 | 93 | public function __construct() { 94 | } 95 | 96 | } 97 | 98 | ?> -------------------------------------------------------------------------------- /sdk/Dropbox/Files.php: -------------------------------------------------------------------------------- 1 | $from_path, "to_path" => $to_path, "allow_shared_folder" => $allow_shared_folder, "autorename" => $autorename, "allow_ownership_transfer" => $allow_ownership_transfer)); 24 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 25 | if (isset($returnData["error"])) { 26 | return $returnData["error_summary"]; 27 | } 28 | else { 29 | return $returnData; 30 | } 31 | } 32 | 33 | /** 34 | * Copies a list of entries between paths 35 | * $entries contains a list of RelocationPath objects (objects with a "from_path" value and a "to_path" value) 36 | * returns either completed response data or an async_job_id if the processing is asynchronous 37 | */ 38 | public function copy_batch($entries, $allow_shared_folder = FALSE, $autorename = FALSE, $allow_ownership_transfer = FALSE) { 39 | $endpoint = "https://api.dropboxapi.com/2/files/copy_batch"; 40 | $headers = array( 41 | "Content-Type: application/json" 42 | ); 43 | $postdata = json_encode(array( "entries" => $entries, "allow_shared_folder" => $allow_shared_folder, "autorename" => $autorename, "allow_ownership_transfer" => $allow_ownership_transfer)); 44 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 45 | if (isset($returnData["error"])) { 46 | return $returnData["error_summary"]; 47 | } 48 | else { 49 | return $returnData; 50 | } 51 | } 52 | 53 | /** 54 | * Checks the progress of an asynchronous copy_batch operation 55 | * 56 | */ 57 | public function copy_batch_check($async_job_id) { 58 | $endpoint = "https://api.dropboxapi.com/2/files/copy_batch/check"; 59 | $headers = array( 60 | "Content-Type: application/json" 61 | ); 62 | $postdata = json_encode(array( "async_job_id" => $async_job_id )); 63 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 64 | if (isset($returnData["error"])) { 65 | return $returnData["error_summary"]; 66 | } 67 | else { 68 | return $returnData; 69 | } 70 | } 71 | 72 | /** 73 | * Get a copy reference to a file or folder. 74 | * This reference string can be used to save that file or folder to another user's Dropbox by passing it to copy_reference/save 75 | */ 76 | public function copy_reference_get($path) { 77 | $endpoint = "https://api.dropboxapi.com/2/files/copy_reference/get"; 78 | $headers = array( 79 | "Content-Type: application/json" 80 | ); 81 | $postdata = json_encode(array( "path" => $path )); 82 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 83 | if (isset($returnData["error"])) { 84 | return $returnData["error_summary"]; 85 | } 86 | else { 87 | return $returnData; 88 | } 89 | } 90 | 91 | /** 92 | * Save a copy reference returned by copy_reference/get to the user's Dropbox 93 | */ 94 | public function copy_reference_save($path, $copy_reference) { 95 | $endpoint = "https://api.dropboxapi.com/2/files/copy_reference/save"; 96 | $headers = array( 97 | "Content-Type: application/json" 98 | ); 99 | $postdata = json_encode(array( "copy_reference" => $copy_reference, "path" => $path )); 100 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 101 | if (isset($returnData["error"])) { 102 | return $returnData["error_summary"]; 103 | } 104 | else { 105 | return $returnData; 106 | } 107 | } 108 | 109 | /** 110 | * Copies a file from one location to another 111 | * 112 | */ 113 | public function copy_v2($from_path, $to_path, $allow_shared_folder = FALSE, $autorename = FALSE, $allow_ownership_transfer = FALSE) { 114 | $endpoint = "https://api.dropboxapi.com/2/files/copy_v2"; 115 | $headers = array( 116 | "Content-Type: application/json" 117 | ); 118 | $postdata = json_encode(array( "from_path" => $from_path, "to_path" => $to_path, "allow_shared_folder" => $allow_shared_folder, "autorename" => $autorename, "allow_ownership_transfer" => $allow_ownership_transfer)); 119 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 120 | if (isset($returnData["error"])) { 121 | return $returnData["error_summary"]; 122 | } 123 | else { 124 | return $returnData; 125 | } 126 | } 127 | 128 | /** 129 | * creates a folder at a given path 130 | * DEPRECATED BY create_folder_v2 131 | */ 132 | public function create_folder($path, $autorename = FALSE) { 133 | $endpoint = "https://api.dropboxapi.com/2/files/create_folder"; 134 | $headers = array( 135 | "Content-Type: application/json" 136 | ); 137 | $postdata = json_encode(array( "path" => $path, "autorename" => $autorename )); 138 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 139 | if (isset($returnData["error"])) { 140 | return $returnData["error_summary"]; 141 | } 142 | else { 143 | return $returnData; 144 | } 145 | } 146 | 147 | /** 148 | * creates a folder at a given path 149 | */ 150 | public function create_folder_v2($path, $autorename = FALSE) { 151 | $endpoint = "https://api.dropboxapi.com/2/files/create_folder_v2"; 152 | $headers = array( 153 | "Content-Type: application/json" 154 | ); 155 | $postdata = json_encode(array( "path" => $path, "autorename" => $autorename )); 156 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 157 | if (isset($returnData["error"])) { 158 | return $returnData["error_summary"]; 159 | } 160 | else { 161 | return $returnData; 162 | } 163 | } 164 | 165 | /** 166 | * deletes a file or folder at a given path 167 | * DEPRECATED by delete_v2 168 | */ 169 | public function delete($path) { 170 | $endpoint = "https://api.dropboxapi.com/2/files/delete"; 171 | $headers = array( 172 | "Content-Type: application/json" 173 | ); 174 | $postdata = json_encode(array( "path" => $path )); 175 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 176 | if (isset($returnData["error"])) { 177 | return $returnData["error_summary"]; 178 | } 179 | else { 180 | return $returnData; 181 | } 182 | } 183 | 184 | 185 | /** 186 | * deletes files and/or folders in $entries 187 | * $entries contains a list of a single value "path" 188 | */ 189 | public function delete_batch($entries) { 190 | $endpoint = "https://api.dropboxapi.com/2/files/delete_batch"; 191 | $headers = array( 192 | "Content-Type: application/json" 193 | ); 194 | $postdata = json_encode(array( "entries" => $entries )); 195 | return Dropbox::postRequest($endpoint, $headers, $postdata); 196 | } 197 | 198 | 199 | /** 200 | * Checks the progress of an asynchronous delete_batch operation 201 | * 202 | */ 203 | public function delete_batch_check($async_job_id) { 204 | $endpoint = "https://api.dropboxapi.com/2/files/delete_batch/check"; 205 | $headers = array( 206 | "Content-Type: application/json" 207 | ); 208 | $postdata = json_encode(array( "async_job_id" => $async_job_id )); 209 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 210 | if (isset($returnData["error"])) { 211 | return $returnData["error_summary"]; 212 | } 213 | else { 214 | return $returnData; 215 | } 216 | } 217 | 218 | /** 219 | * deletes a file or folder at a given path 220 | * 221 | */ 222 | public function delete_v2($path) { 223 | $endpoint = "https://api.dropboxapi.com/2/files/delete_v2"; 224 | $headers = array( 225 | "Content-Type: application/json" 226 | ); 227 | $postdata = json_encode(array( "path" => $path )); 228 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 229 | if (isset($returnData["error"])) { 230 | return $returnData["error_summary"]; 231 | } 232 | else { 233 | return $returnData; 234 | } 235 | } 236 | 237 | /** 238 | * downloads a file to the given path 239 | * pass false to $target to return rawdata 240 | */ 241 | public function download($path, $target) { 242 | $endpoint = "https://content.dropboxapi.com/2/files/download"; 243 | $headers = array( 244 | "Content-Type: ", 245 | "Dropbox-API-Arg: {\"path\": \"$path\"}" 246 | ); 247 | $returnData = Dropbox::postRequest($endpoint, $headers, '', FALSE); 248 | if ($target !== false) { 249 | $file = fopen($target, 'w'); 250 | fwrite($file, $returnData); 251 | fclose($file); 252 | } 253 | else { 254 | return $returnData; 255 | } 256 | } 257 | 258 | /** 259 | * Returns the metadata for a file or folder 260 | */ 261 | public function get_metadata($path, $include_media_info = FALSE, $include_deleted = FALSE, $include_has_explicit_shared_members = FALSE) { 262 | $endpoint = "https://api.dropboxapi.com/2/files/get_metadata"; 263 | $headers = array( 264 | "Content-Type: application/json", 265 | ); 266 | $postdata = json_encode(array( "path" => $path, "include_media_info" => $include_media_info, "include_deleted" => $include_deleted, "include_has_explicit_shared_members" => $include_has_explicit_shared_members)); 267 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 268 | if (isset($returnData["error"])) { 269 | return $returnData["error_summary"]; 270 | } 271 | else { 272 | return $returnData; 273 | } 274 | } 275 | 276 | /** 277 | * gets a preview for a file 278 | * $path: the dropbox path, id:, rev:, of a file 279 | * $target: where the file is being downloaded to 280 | */ 281 | public function get_preview($path, $target) { 282 | $endpoint = "https://content.dropboxapi.com/2/files/get_preview"; 283 | $headers = array( 284 | "Dropbox-API-Arg: {\"path\": \"$path\"}" 285 | ); 286 | $returnData = Dropbox::postRequest($endpoint, $headers, '', FALSE); 287 | // check for errors 288 | $eData = json_decode($returnData, true); 289 | if (isset($eData["error"])) { 290 | return $eData["error_summary"]; 291 | } 292 | else { 293 | $file = fopen($target, 'w'); 294 | fwrite($file, $returnData); 295 | fclose($file); 296 | } 297 | } 298 | 299 | /** 300 | * gets a termporary link to stream content of a file 301 | * the link expires in 4 hours, after which it will return 410 GONE 302 | */ 303 | public function get_temporary_link($path) { 304 | $endpoint = "https://api.dropboxapi.com/2/files/get_temporary_link"; 305 | $headers = array( 306 | "Content-Type: application/json" 307 | ); 308 | $postdata = json_encode(array( "path" => $path )); 309 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 310 | if (isset($returnData["error"])) { 311 | return $returnData["error_summary"]; 312 | } 313 | else { 314 | return $returnData; 315 | } 316 | } 317 | 318 | /** 319 | * gets the thumbnail for an image 320 | * $format: jpeg or png 321 | * $size: default w64h64 322 | */ 323 | public function get_thumbnail($path, $target, $format = 'jpeg', $size = 'w64h64') { 324 | $endpoint = "https://content.dropboxapi.com/2/files/get_thumbnail"; 325 | 326 | $headers = array( 327 | "Content-Type: application/octet-stream", 328 | "Dropbox-API-Arg: {\"path\": \"$path\", \"format\": \"$format\", \"size\": \"$size\"}" 329 | ); 330 | 331 | $returnData = Dropbox::postRequest($endpoint, $headers, '', FALSE); 332 | 333 | // Check for Errors 334 | 335 | $eData = json_decode($returnData, true); 336 | 337 | if (isset($eData["error"])) { 338 | return $eData["error_summary"]; 339 | } 340 | else { 341 | $file = fopen($target, 'w'); 342 | fwrite($file, $returnData); 343 | fclose($file); 344 | } 345 | } 346 | 347 | public function getThumbnailSize($size) 348 | { 349 | $thumbnailSizes = array( 350 | 'thumb' => 'w32h32', 351 | 'small' => 'w64h64', 352 | 'medium' => 'w128h128', 353 | 'large' => 'w640h480', 354 | 'huge' => 'w1024h768' 355 | ); 356 | return isset($thumbnailSizes[$size]) ? $thumbnailSizes[$size] : $thumbnailSizes['small']; 357 | } 358 | 359 | public function getContents($file) 360 | { 361 | return $file->contents; 362 | } 363 | 364 | /** 365 | * gets the contents of a folder 366 | */ 367 | public function list_folder($path, $recursive = FALSE, $include_media_info = FALSE, $include_has_explicit_shared_members = FALSE) { 368 | $endpoint = "https://api.dropboxapi.com/2/files/list_folder"; 369 | $headers = array( 370 | "Content-Type: application/json", 371 | ); 372 | $postdata = json_encode(array( "path" => $path, "recursive" => $recursive, "include_media_info" => $include_media_info, "include_has_explicit_shared_members" => $include_has_explicit_shared_members)); 373 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 374 | if (isset($returnData["error"])) { 375 | return $returnData["error_summary"]; 376 | } 377 | else { 378 | return $returnData; 379 | } 380 | } 381 | 382 | /** 383 | * continue listing the contents of a folder given a cursor from list_folder or 384 | * a previous call of list_folder_continue 385 | */ 386 | public function list_folder_continue($cursor) { 387 | $endpoint = "https://api.dropboxapi.com/2/files/list_folder/continue"; 388 | $headers = array( 389 | "Content-Type: application/json", 390 | ); 391 | $postdata = json_encode(array( "cursor" => $cursor)); 392 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 393 | if (isset($returnData["error"])) { 394 | return $returnData["error_summary"]; 395 | } 396 | else { 397 | return $returnData; 398 | } 399 | } 400 | 401 | /** 402 | * gets the latest cursor for a folder 403 | */ 404 | public function get_latest_cursor($path, $recursive = FALSE, $include_media_info = FALSE, $include_deleted = FALSE, $include_has_explicit_shared_members = FALSE) { 405 | $endpoint = "https://api.dropboxapi.com/2/files/list_folder/get_latest_cursor"; 406 | $headers = array( 407 | "Content-Type: application/json", 408 | ); 409 | $postdata = json_encode(array( "path" => $path, "recursive" => $recursive, "include_media_info" => $include_media_info, "include_deleted" => $include_deleted, "include_has_explicit_shared_members" => $include_has_explicit_shared_members)); 410 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 411 | if (isset($returnData["error"])) { 412 | return $returnData["error_summary"]; 413 | } 414 | else { 415 | return $returnData; 416 | } 417 | } 418 | 419 | /** 420 | * A longpoll endpoint to wait for changes on an account. 421 | * In conjunction with list_folder/continue, this call gives you a low-latency way to monitor an account for file changes. 422 | * The connection will block until there are changes available or a timeout occurs. This endpoint is useful mostly for client-side apps. 423 | */ 424 | public function list_folder_longpoll($cursor, $timeout = 30) { 425 | $endpoint = "https://notify.dropboxapi.com/2/files/list_folder/longpoll"; 426 | $headers = array( 427 | "Content-Type: application/json", 428 | ); 429 | $postdata = json_encode(array( "cursor" => $cursor, "timeout" => $timeout)); 430 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 431 | if (isset($returnData["error"])) { 432 | return $returnData["error_summary"]; 433 | } 434 | else { 435 | return $returnData; 436 | } 437 | } 438 | 439 | /** 440 | * returns the revisions of a file 441 | */ 442 | public function list_revisions($path, $limit = 10) { 443 | $endpoint = "https://api.dropboxapi.com/2/files/list_revisions"; 444 | $headers = array( 445 | "Content-Type: application/json", 446 | ); 447 | $postdata = json_encode(array( "path" => $path, "limit" => $limit)); 448 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 449 | if (isset($returnData["error"])) { 450 | return $returnData["error_summary"]; 451 | } 452 | else { 453 | return $returnData; 454 | } 455 | } 456 | 457 | /** 458 | * moves a file from one location to another 459 | * DEPRECATED by move_v2 460 | */ 461 | public function move($from_path, $to_path, $allow_shared_folder = FALSE, $autorename = FALSE, $allow_ownership_transfer = FALSE) { 462 | $endpoint = "https://api.dropboxapi.com/2/files/move"; 463 | $headers = array( 464 | "Content-Type: application/json" 465 | ); 466 | $postdata = json_encode(array( "from_path" => $from_path, "to_path" => $to_path, "allow_shared_folder" => $allow_shared_folder, "autorename" => $autorename, "allow_ownership_transfer" => $allow_ownership_transfer)); 467 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 468 | if (isset($returnData["error"])) { 469 | return $returnData["error_summary"]; 470 | } 471 | else { 472 | return $returnData; 473 | } 474 | } 475 | 476 | /** 477 | * moves a list of entries between paths 478 | * $entries contains a list of RelocationPath objects (objects with a "from_path" value and a "to_path" value) 479 | * returns either completed response data or an async_job_id if the processing is asynchronous 480 | */ 481 | public function move_batch($entries, $allow_shared_folder = FALSE, $autorename = FALSE, $allow_ownership_transfer = FALSE) { 482 | $endpoint = "https://api.dropboxapi.com/2/files/move_batch"; 483 | $headers = array( 484 | "Content-Type: application/json" 485 | ); 486 | $postdata = json_encode(array( "entries" => $entries, "allow_shared_folder" => $allow_shared_folder, "autorename" => $autorename, "allow_ownership_transfer" => $allow_ownership_transfer)); 487 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 488 | if (isset($returnData["error"])) { 489 | return $returnData["error_summary"]; 490 | } 491 | else { 492 | return $returnData; 493 | } 494 | } 495 | 496 | /** 497 | * Checks the progress of an asynchronous move_batch operation 498 | * 499 | */ 500 | public function move_batch_check($async_job_id) { 501 | $endpoint = "https://api.dropboxapi.com/2/files/move_batch/check"; 502 | $headers = array( 503 | "Content-Type: application/json" 504 | ); 505 | $postdata = json_encode(array( "async_job_id" => $async_job_id )); 506 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 507 | if (isset($returnData["error"])) { 508 | return $returnData["error_summary"]; 509 | } 510 | else { 511 | return $returnData; 512 | } 513 | } 514 | 515 | /** 516 | * moves a file from one location to another 517 | */ 518 | public function move_v2($from_path, $to_path, $allow_shared_folder = FALSE, $autorename = FALSE, $allow_ownership_transfer = FALSE) { 519 | $endpoint = "https://api.dropboxapi.com/2/files/move_v2"; 520 | $headers = array( 521 | "Content-Type: application/json" 522 | ); 523 | $postdata = json_encode(array( "from_path" => $from_path, "to_path" => $to_path, "allow_shared_folder" => $allow_shared_folder, "autorename" => $autorename, "allow_ownership_transfer" => $allow_ownership_transfer)); 524 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 525 | if (isset($returnData["error"])) { 526 | return $returnData["error_summary"]; 527 | } 528 | else { 529 | return $returnData; 530 | } 531 | } 532 | 533 | /** 534 | * permanently deletes a file or folder 535 | * Note: this endpoint is only available for Dropbox Business apps 536 | */ 537 | public function permanently_delete($path) { 538 | $endpoint = "https://api.dropboxapi.com/2/files/permanently_delete"; 539 | $headers = array( 540 | "Content-Type: application/json" 541 | ); 542 | $postdata = json_encode(array( "path" => $path)); 543 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 544 | if (isset($returnData["error"])) { 545 | return $returnData["error_summary"]; 546 | } 547 | else { 548 | return $returnData; 549 | } 550 | } 551 | 552 | /** 553 | * restore a file to a specific revision 554 | */ 555 | public function restore($path, $rev) { 556 | $endpoint = "https://api.dropboxapi.com/2/files/restore"; 557 | $headers = array( 558 | "Content-Type: application/json" 559 | ); 560 | $postdata = json_encode(array( "path" => $path, "rev" => $rev)); 561 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 562 | if (isset($returnData["error"])) { 563 | return $returnData["error_summary"]; 564 | } 565 | else { 566 | return $returnData; 567 | } 568 | } 569 | 570 | /** 571 | * saves a specified URL into a file in user's Dropbox 572 | */ 573 | public function save_url($path, $url) { 574 | $endpoint = "https://api.dropboxapi.com/2/files/save_url"; 575 | $headers = array( 576 | "Content-Type: application/json" 577 | ); 578 | $postdata = json_encode(array( "path" => $path, "url" => $url)); 579 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 580 | if (isset($returnData["error"])) { 581 | return $returnData["error_summary"]; 582 | } 583 | else { 584 | return $returnData; 585 | } 586 | } 587 | 588 | /** 589 | * Checks the progress of an asynchronous save_url operation 590 | */ 591 | public function save_url_check_job_status($async_job_id) { 592 | $endpoint = "https://api.dropboxapi.com/2/files/save_url/check_job_status"; 593 | $headers = array( 594 | "Content-Type: application/json" 595 | ); 596 | $postdata = json_encode(array( "async_job_id" => $async_job_id )); 597 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 598 | if (isset($returnData["error"])) { 599 | return $returnData["error_summary"]; 600 | } 601 | else { 602 | return $returnData; 603 | } 604 | } 605 | 606 | /** 607 | * searches for files and folders 608 | * $query, the string to search for 609 | * $start, starting index (default 0) 610 | * $max_results, maximum number of results (default 100) 611 | * $mode, SearchMode 'filename', 'filename_and_content', 'deleted_filename' (default filename) 612 | */ 613 | public function search($path, $query, $start = 0, $max_results = 100, $mode = "filename") { 614 | $endpoint = "https://api.dropboxapi.com/2/files/search"; 615 | $headers = array( 616 | "Content-Type: application/json" 617 | ); 618 | $postdata = json_encode(array( "path" => $path, "query" => $query, "start" => $start, "max_results" => $max_results, "mode" => $mode)); 619 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 620 | if (isset($returnData["error"])) { 621 | return $returnData["error_summary"]; 622 | } 623 | else { 624 | return $returnData; 625 | } 626 | } 627 | 628 | /* 629 | * $file_data can be either raw string data or a path to a file 630 | * @parameter $mode: "add", "update", "overwrite" 631 | */ 632 | public function upload($target_path, $file_data, $mode = "add") { 633 | $endpoint = "https://content.dropboxapi.com/2/files/upload"; 634 | $headers = array( 635 | "Content-Type: application/octet-stream", 636 | "Dropbox-API-Arg: {\"path\": \"$target_path\", \"mode\": \"$mode\"}" 637 | ); 638 | $postdata = ""; 639 | if (file_exists($file_data)) 640 | $postdata = file_get_contents($file_data); 641 | else 642 | $postdata = $file_data; 643 | 644 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 645 | if (isset($returnData["error"])) { 646 | return $returnData["error_summary"]; 647 | } 648 | else { 649 | return $returnData["path_display"]; 650 | } 651 | } 652 | 653 | /** 654 | * append more data to an upload session. 655 | * a single request should not upload more than 150 MB. 656 | * DEPRECATED by upload_session/append_v2 657 | */ 658 | public function upload_session_append($session_id, $offset, $file_path) { 659 | $endpoint = "https://content.dropboxapi.com/2/files/upload_session/append"; 660 | $headers = array( 661 | "Content-Type: application/octet-stream", 662 | "Dropbox-API-Arg: {\"session_id\": \"$session_id\", \"offset\": \"$offset\"}" 663 | ); 664 | $postdata = file_get_contents($file_path); 665 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 666 | if (isset($returnData["error"])) { 667 | return $returnData["error_summary"]; 668 | } 669 | else { 670 | return true; 671 | } 672 | } 673 | 674 | /** 675 | * append more data to an upload session. 676 | * a single request should not upload more than 150 MB. 677 | */ 678 | public function upload_session_append_v2($session_id, $offset, $file_path, $close = FALSE) { 679 | $endpoint = "https://content.dropboxapi.com/2/files/upload_session/append_v2"; 680 | $headers = array( 681 | "Content-Type: application/octet-stream", 682 | "Dropbox-API-Arg: {\"cursor\": {\"session_id\": \"$session_id\", \"offset\": \"$offset\"}, \"close\": $close}" 683 | ); 684 | $postdata = file_get_contents($file_path); 685 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 686 | if (isset($returnData["error"])) { 687 | return $returnData["error_summary"]; 688 | } 689 | else { 690 | return true; 691 | } 692 | } 693 | 694 | /* 695 | * Entry must be an instanceof Entry (Dropbox\Entry) 696 | */ 697 | public function upload_session_finish(Entry $entry) { 698 | $endpoint = "https://content.dropboxapi.com/2/files/upload_session/finish"; 699 | $headers = array( 700 | "Content-Type" => 'application/octet-stream', 701 | "Dropbox-API-Arg" => $entry.toJson() 702 | ); 703 | $headers = json_encode($headers); 704 | $postdata = file_get_contents($file_path); 705 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 706 | if (isset($returnData["error"])) { 707 | return $returnData["error_summary"]; 708 | } 709 | else { 710 | return $returnData; 711 | } 712 | } 713 | 714 | /** 715 | * Finishes uploading a list of elements 716 | * $entries contains a list of elements of type 'Entry' 717 | * returns either completed response data or an async_job_id if the processing is asynchronous 718 | */ 719 | public function finish_batch($entries) { 720 | $endpoint = "https://api.dropboxapi.com/2/files/finish_batch"; 721 | $headers = array( 722 | "Content-Type: application/json" 723 | ); 724 | $postdata = json_encode(array( "entries" => $entries )); 725 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 726 | if (isset($returnData["error"])) { 727 | return $returnData["error_summary"]; 728 | } 729 | else { 730 | return $returnData; 731 | } 732 | } 733 | 734 | /** 735 | * Checks the progress of an asynchronous finish_batch operation 736 | */ 737 | public function finish_batch_check($async_job_id) { 738 | $endpoint = "https://api.dropboxapi.com/2/files/finish_batch/check"; 739 | $headers = array( 740 | "Content-Type: application/json" 741 | ); 742 | $postdata = json_encode(array( "async_job_id" => $async_job_id )); 743 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 744 | if (isset($returnData["error"])) { 745 | return $returnData["error_summary"]; 746 | } 747 | else { 748 | return $returnData; 749 | } 750 | } 751 | 752 | /* 753 | * starts an upload session, needed where the size of a file is greater than 150 MB 754 | * can last up to 48 hours 755 | */ 756 | public function upload_session_start($file_path, $close = false) { 757 | $endpoint = "https://content.dropboxapi.com/2/files/upload_session/start"; 758 | $headers = array( 759 | "Content-Type: application/octet-stream", 760 | "Dropbox-API-Arg: {\"close\": $close}" 761 | ); 762 | $postdata = file_get_contents($file_path); 763 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 764 | if (isset($returnData["error"])) { 765 | return $returnData["error_summary"]; 766 | } 767 | else { 768 | return $returnData["session_id"]; 769 | } 770 | 771 | } 772 | 773 | // * * ***** **** **** 774 | // ** ** * * * 775 | // * * * * *** * 776 | // * * * * * 777 | // * * ***** **** **** * 778 | 779 | public function __construct() { 780 | } 781 | 782 | } 783 | 784 | ?> 785 | -------------------------------------------------------------------------------- /sdk/Dropbox/Misc.php: -------------------------------------------------------------------------------- 1 | $path, "include_media_info" => FALSE, "include_deleted" => FALSE, "include_has_explicit_shared_members" => false)); 22 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 23 | if (isset($returnData["error"])) { 24 | return FALSE; 25 | } 26 | else { 27 | return TRUE; 28 | } 29 | } 30 | } 31 | 32 | class Entry { 33 | public $cursor; 34 | public $commit; 35 | 36 | public function __construct($session_id, $offset, $path, $mode = 'add', $autorename = false, $mute = false) { 37 | $this->cursor = array( 38 | "session_id" => $session_id, 39 | "offset" => $offset 40 | ); 41 | $this->commit = array( 42 | "path" => $path, 43 | "mode" => $mode, 44 | "autorename" => $autorename, 45 | "mute" => $mute 46 | ); 47 | } 48 | 49 | public function toJson() { 50 | return json_encode(array( 51 | "cursor" => $this->cursor, 52 | "commit" => $this->commit 53 | )); 54 | } 55 | } 56 | 57 | ?> -------------------------------------------------------------------------------- /sdk/Dropbox/Paper.php: -------------------------------------------------------------------------------- 1 | $doc_id )); 22 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 23 | if (isset($returnData["error"])) { 24 | return $returnData["error_summary"]; 25 | } 26 | else { 27 | return $returnData; 28 | } 29 | } 30 | /* 31 | * creates a new Paper doc with the provided content. 32 | * $import_format: 'plain_text', 'html' or 'markdown' 33 | * $parent_folder_id: The Paper folder ID where the Paper document should be created. The API user has to have write access to this folder or error is thrown. This field is optional. 34 | */ 35 | public function create($import_format, $file_path, $parent_folder_id = null) { 36 | $endpoint = "https://api.dropboxapi.com/2/docs/create"; 37 | $Dropbox_API_Arg = ""; 38 | if ($parent_folder_id == null) { 39 | $Dropbox_API_Arg = "{\"import_format\": $import_format}"; 40 | } 41 | else { 42 | $Dropbox_API_Arg = "{\"import_format\": $import_format, \"parent_folder_id\": $parent_folder_id}"; 43 | } 44 | $headers = array( 45 | "Content-Type: application/octet-stream", 46 | "Dropbox-API-Arg: $Dropbox_API_Arg" 47 | ); 48 | $postdata = file_get_contents($file_path); 49 | 50 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 51 | if (isset($returnData["error"])) { 52 | return $returnData["error_summary"]; 53 | } 54 | else { 55 | return $returnData; 56 | } 57 | } 58 | 59 | /* 60 | * Exports and downloads Paper doc either as HTML or markdown 61 | * $export_format: either 'html' or 'markdown' 62 | */ 63 | public function download($doc_id, $export_format) { 64 | $endpoint = "https://api.dropboxapi.com/2/docs/download"; 65 | $headers = array( 66 | "Content-Type: application/json" 67 | ); 68 | $postdata = json_encode(array( "doc_id" => $doc_id, "export_format" => $export_format )); 69 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 70 | if (isset($returnData["error"])) { 71 | return $returnData["error_summary"]; 72 | } 73 | else { 74 | return $returnData; 75 | } 76 | } 77 | 78 | /* 79 | * Lists the users who are explicitly invited to the Paper folder in which the Paper doc is contained. For private folders all users (including owner) 80 | * shared on the folder are listed and for team folders all non-team users shared on the folder are returned. 81 | */ 82 | public function folder_users_list($doc_id, $limit = 1000) { 83 | $endpoint = "https//api.dropboxapi.com/2/paper/docs/folder_users/list"; 84 | $headers = array( 85 | "Content-Type: application/json" 86 | ); 87 | $postdata = json_encode(array( "doc_id" => $doc_id, "limit" => $limit)); 88 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 89 | if (isset($returnData["error"])) { 90 | return $returnData["error_summary"]; 91 | } 92 | else { 93 | return $returnData; 94 | } 95 | } 96 | 97 | /* 98 | * Once a cursor has been retrieved from docs/folder_users/list, use this to paginate through all users on the Paper folder. 99 | */ 100 | public function folder_users_list_continue($doc_id, $cursor) { 101 | $endpoint = "https//api.dropboxapi.com/2/paper/docs/folder_users/list/continue"; 102 | $headers = array( 103 | "Content-Type: application/json" 104 | ); 105 | $postdata = json_encode(array( "doc_id" => $doc_id, "cursor" => $cursor)); 106 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 107 | if (isset($returnData["error"])) { 108 | return $returnData["error_summary"]; 109 | } 110 | else { 111 | return $returnData; 112 | } 113 | } 114 | 115 | /* 116 | * Retrieves folder information for the given Paper doc. 117 | */ 118 | public function get_folder_info($doc_id) { 119 | $endpoint = "https://api.dropboxapi.com/2/paper/docs/get_folder_info"; 120 | $headers = array( 121 | "Content-Type: application/json" 122 | ); 123 | $postdata = json_encode(array( "doc_id" => $doc_id)); 124 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 125 | if (isset($returnData["error"])) { 126 | return $returnData["error_summary"]; 127 | } 128 | else { 129 | return $returnData; 130 | } 131 | } 132 | 133 | /* 134 | * Returns the list of all Paper docs according to the argument specifications. 135 | */ 136 | public function llist($filter_by = "docs_accessed", $sort_by = "accessed", $sort_order = "ascending", $limit = 1000) { 137 | $endpoint = "https//api.dropboxapi.com/2/paper/docs/list"; 138 | $headers = array( 139 | "Content-Type: application/json" 140 | ); 141 | $postdata = json_encode(array( "filter_by" => $filter_by, "sort_by" => $sort_by, "sort_order" => $sort_order, "limit" => $limit)); 142 | return Dropbox::postRequest($endpoint, $headers, $postdata); 143 | } 144 | 145 | public function list_continue($cursor) { 146 | $endpoint = "https//api.dropboxapi.com/2/paper/docs/list/continue"; 147 | $headers = array( 148 | "Content-Type: application/json" 149 | ); 150 | $postdata = json_encode(array( "cursor" => $cursor)); 151 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 152 | if (isset($returnData["error"])) { 153 | return $returnData["error_summary"]; 154 | } 155 | else { 156 | return $returnData; 157 | } 158 | } 159 | 160 | /* 161 | * permanently deletes the given Paper doc. 162 | */ 163 | public function permanently_delete($doc_id) { 164 | $endpoint = "https//api.dropboxapi.com/2/paper/docs/permanently_delete"; 165 | $headers = array( 166 | "Content-Type: application/json" 167 | ); 168 | $postdata = json_encode(array( "doc_id" => $doc_id)); 169 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 170 | if (isset($returnData["error"])) { 171 | return $returnData["error_summary"]; 172 | } 173 | else { 174 | return $returnData; 175 | } 176 | } 177 | 178 | /* 179 | * returns the default sharing policy for the given Paper doc 180 | */ 181 | public function sharing_policy_get($doc_id) { 182 | $endpoint = "https//api.dropboxapi.com/2/paper/docs/sharing_policy/get"; 183 | $headers = array( 184 | "Content-Type: application/json" 185 | ); 186 | $postdata = json_encode(array( "doc_id" => $doc_id)); 187 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 188 | if (isset($returnData["error"])) { 189 | return $returnData["error_summary"]; 190 | } 191 | else { 192 | return $returnData; 193 | } 194 | } 195 | 196 | /* 197 | * Sets the default sharing policy for the given Paper doc. The default 198 | * 'team_sharing_policy' can be changed only by teams, omit this field for personal accounts. 199 | * 200 | * Note: 'public_sharing_policy' cannot be set to the value 'disabled' 201 | * because this setting can be changed only via the team admin console. 202 | */ 203 | public function sharing_policy_set($doc_id, $public_sharing_policy, $team_sharing_policy = "") { 204 | $endpoint = "https//api.dropboxapi.com/2/paper/docs/sharing_policy/set"; 205 | $headers = array( 206 | "Content-Type: application/json" 207 | ); 208 | $postdata = json_encode(array( "doc_id" => $doc_id, "sharing_policy" => array( "public_sharing_policy" => $public_sharing_policy, "team_sharing_policy" => $team_sharing_policy))); 209 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 210 | if (isset($returnData["error"])) { 211 | return $returnData["error_summary"]; 212 | } 213 | else { 214 | return $returnData; 215 | } 216 | } 217 | 218 | /* 219 | * updates an existing Paper doc with the provided content 220 | */ 221 | public function update($doc_id, $doc_update_policy, $revision, $import_format) { 222 | $endpoint = "https//api.dropboxapi.com/2/paper/docs/update"; 223 | $headers = array( 224 | "Content-Type: application/json" 225 | ); 226 | $postdata = json_encode(array( "doc_id" => $doc_id, "doc_update_policy" => $doc_update_policy, "revision" => $revision, "import_format" => $import_format)); 227 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 228 | if (isset($returnData["error"])) { 229 | return $returnData["error_summary"]; 230 | } 231 | else { 232 | return $returnData; 233 | } 234 | } 235 | 236 | /* 237 | * Allows an owner or editor to add users to a Paper doc or change their 238 | * permissions using their email address or Dropbox account ID. 239 | * please read the documentation for the $members format 240 | */ 241 | public function users_add($doc_id, $members, $quiet = false, $custom_message = null) { 242 | $endpoint = "https//api.dropboxapi.com/2/paper/docs/users/add"; 243 | $headers = array( 244 | "Content-Type: application/json" 245 | ); 246 | $postdata = json_encode(array( "doc_id" => $doc_id, "members" => $members, "quiet" => $quiet)); 247 | if (is_null($custom_message) == FALSE) { 248 | array_push($postdata, $custom_message); 249 | } 250 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 251 | if (isset($returnData["error"])) { 252 | return $returnData["error_summary"]; 253 | } 254 | else { 255 | return $returnData; 256 | } 257 | } 258 | 259 | /* 260 | * lists all users who visited the Paper doc or users with explicit access. 261 | */ 262 | public function users_list($doc_id, $limit = 1000, $filter_by = "shared") { 263 | $endpoint = "https//api.dropboxapi.com/2/paper/docs/users/list"; 264 | $headers = array( 265 | "Content-Type: application/json" 266 | ); 267 | $postdata = json_encode(array( "doc_id" => $doc_id, "limit" => $limit, "filter_by" => $filter_by)); 268 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 269 | if (isset($returnData["error"])) { 270 | return $returnData["error_summary"]; 271 | } 272 | else { 273 | return $returnData; 274 | } 275 | } 276 | 277 | public function users_list_continue($doc_id, $cursor) { 278 | $endpoint = "https//api.dropboxapi.com/2/paper/docs/users/list/continue"; 279 | $headers = array( 280 | "Content-Type: application/json" 281 | ); 282 | $postdata = json_encode(array( "doc_id" => $doc_id, "cursor" => $cursor)); 283 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 284 | if (isset($returnData["error"])) { 285 | return $returnData["error_summary"]; 286 | } 287 | else { 288 | return $returnData; 289 | } 290 | } 291 | 292 | /* 293 | * Allows an owner or editor to remove users from a Paper doc using their email address or Dropbox account ID. 294 | */ 295 | public function users_remove($doc_id, $member) { 296 | $endpoint = "https//api.dropboxapi.com/2/paper/docs/users/remove"; 297 | $headers = array( 298 | "Content-Type: application/json" 299 | ); 300 | $postdata = json_encode(array( "doc_id" => $doc_id, "member" => $member)); 301 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 302 | if (isset($returnData["error"])) { 303 | return $returnData["error_summary"]; 304 | } 305 | else { 306 | return $returnData; 307 | } 308 | } 309 | 310 | 311 | public function __construct() { 312 | } 313 | } 314 | 315 | ?> -------------------------------------------------------------------------------- /sdk/Dropbox/Sharing.php: -------------------------------------------------------------------------------- 1 | $file, "members" => $members, "quiet" => $quiet, "access_level" => $access_level, "add_mesage_as_comment" => $add_message_as_comment ); 23 | if (is_null($custom_message) == FALSE) 24 | $postarray["custom_message"] = $custom_message; 25 | $postdata = json_encode($postarray); 26 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 27 | if (isset($returnData["error"])) { 28 | return $returnData["error_summary"]; 29 | } 30 | else { 31 | return $returnData; 32 | } 33 | } 34 | 35 | /* 36 | * adds specified members to a folder 37 | */ 38 | public function add_folder_member($file, $members, $quiet = FALSE, $custom_message = null) { 39 | $endpoint = "https://api.dropboxapi.com/2/sharing/add_folder_member"; 40 | $headers = array( 41 | "Content-Type: application/json" 42 | ); 43 | $postarray = array( "file" => $file, "members" => $members, "quiet" => $quiet ); 44 | if (is_null($custom_message) == FALSE) 45 | $postarray["custom_message"] = $custom_message; 46 | $postdata = json_encode($postarray); 47 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 48 | if (isset($returnData["error"])) { 49 | return $returnData["error_summary"]; 50 | } 51 | else { 52 | return $returnData; 53 | } 54 | } 55 | 56 | /* 57 | * deprecated by /update_file_member 58 | */ 59 | public function change_file_member_access($file, $member, $access_level) { 60 | $endpoint = "https://api.dropboxapi.com/2/sharing/change_file_member_access"; 61 | $headers = array( 62 | "Content-Type: application/json" 63 | ); 64 | $postdata = json_encode(array( "file" => $file, "members" => $member, "access_level" => $access_level )); 65 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 66 | if (isset($returnData["error"])) { 67 | return $returnData["error_summary"]; 68 | } 69 | else { 70 | return $returnData; 71 | } 72 | } 73 | 74 | /* 75 | * returns the status of an asynchronous job 76 | * apps must have full dropbox access to use this endpoint 77 | */ 78 | public function check_job_status($async_job_id) { 79 | $endpoint = "https://api.dropboxapi.com/2/sharing/check_job_status"; 80 | $headers = array( 81 | "Content-Type: application/json" 82 | ); 83 | $postdata = json_encode(array( "async_job_id" => $async_job_id )); 84 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 85 | if (isset($returnData["error"])) { 86 | return $returnData["error_summary"]; 87 | } 88 | else { 89 | return $returnData; 90 | } 91 | } 92 | 93 | /* 94 | * returns the status of an asynchronous job for sharing a folder. 95 | */ 96 | public function check_remove_member_job_status($async_job_id) { 97 | $endpoint = "https://api.dropboxapi.com/2/sharing/check_remove_member_job_status"; 98 | $headers = array( 99 | "Content-Type: application/json" 100 | ); 101 | $postdata = json_encode(array( "async_job_id" => $async_job_id )); 102 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 103 | if (isset($returnData["error"])) { 104 | return $returnData["error_summary"]; 105 | } 106 | else { 107 | return $returnData; 108 | } 109 | } 110 | 111 | /* 112 | * returns the status of an asynchronous job for sharing a folder 113 | */ 114 | public function check_share_job_status($async_job_id) { 115 | $endpoint = "https://api.dropboxapi.com/2/sharing/check_share_job_status"; 116 | $headers = array( 117 | "Content-Type: application/json" 118 | ); 119 | $postdata = json_encode(array( "async_job_id" => $async_job_id)); 120 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 121 | if (isset($returnData["error"])) { 122 | return $returnData["error_summary"]; 123 | } 124 | else { 125 | return $returnData; 126 | } 127 | } 128 | 129 | /* 130 | * deprecated by create_shared_link_with_settings 131 | */ 132 | public function create_shared_link($path, $short_url = FALSE) { 133 | $endpoint = "https://api.dropboxapi.com/2/sharing/create_shared_link"; 134 | $headers = array( 135 | "Content-Type: application/json" 136 | ); 137 | $postdata = json_encode(array( "path" => $path, "short_url" => $short_url)); 138 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 139 | if (isset($returnData["error"])) { 140 | return $returnData["error_summary"]; 141 | } 142 | else { 143 | return $returnData["url"]; 144 | } 145 | } 146 | 147 | public function create_shared_link_with_settings($path) { 148 | $endpoint = "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings"; 149 | $headers = array( 150 | "Content-Type: application/json", 151 | "Dropbox-API-Arg: {\"path\": \"$target_path\", \"mode\": \"$mode\"}" 152 | ); 153 | $postdata = json_encode(array( "path" => $path, "settings" => array( "requested_visibility" => "public"))); 154 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 155 | if (isset($returnData["error"])) { 156 | return $returnData["error_summary"]; 157 | } 158 | else { 159 | return $returnData["url"]; 160 | } 161 | } 162 | 163 | public function get_file_metadata($file, $actions = array()) { 164 | $endpoint = "https://api.dropboxapi.com/2/sharing/get_file_metadata"; 165 | $headers = array( 166 | "Content-Type: application/json" 167 | ); 168 | $postdata = json_encode(array( "file" => $file, "actions" => $actions)); 169 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 170 | if (isset($returnData["error"])) { 171 | return $returnData["error_summary"]; 172 | } 173 | else { 174 | return $returnData; 175 | } 176 | } 177 | 178 | public function get_file_metadata_bath($files, $actions = array()) { 179 | $endpoint = "https://api.dropboxapi.com/2/sharing/get_file_metadata/batch"; 180 | $headers = array( 181 | "Content-Type: application/json" 182 | ); 183 | $postdata = json_encode(array( "files" => $files, "actions" => $actions)); 184 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 185 | if (isset($returnData["error"])) { 186 | return $returnData["error_summary"]; 187 | } 188 | else { 189 | return $returnData; 190 | } 191 | } 192 | 193 | /* 194 | * gets folder metadata 195 | */ 196 | public function get_folder_metadata($shared_folder_id, $actions = array()) { 197 | $endpoint = "https://api.dropboxapi.com/2/sharing/get_folder_metadata"; 198 | $headers = array( 199 | "Content-Type: application/json" 200 | ); 201 | $postdata = json_encode(array( "shared_folder_id" => $shared_folder_id, "actions" => $actions)); 202 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 203 | if (isset($returnData["error"])) { 204 | return $returnData["error_summary"]; 205 | } 206 | else { 207 | return $returnData; 208 | } 209 | } 210 | 211 | /* 212 | * download the shared link's file from a user's Dropbox 213 | */ 214 | public function get_shared_link_file($url, $path = null, $link_password = null) { 215 | $endpoint = "https://api.dropboxapi.com/2/sharing/get_file_metadata/batch"; 216 | $data_array = array( "url" => $url); 217 | if (is_null($path) == FALSE) { 218 | $data_array["path"] = $path; 219 | } 220 | if (is_null($link_password) == FALSE) { 221 | $data_array["link_password"] = $link_password; 222 | } 223 | $data_array = json_encode($data_array); 224 | $headers = array( 225 | "Content-Type: application/json", 226 | "Dropbox-API-Arg: { $data_array }" 227 | ); 228 | $returnData = Dropbox::postRequest($endpoint, $headers, ""); 229 | if (isset($returnData["error"])) { 230 | return $returnData["error_summary"]; 231 | } 232 | else { 233 | return $returnData; 234 | } 235 | } 236 | 237 | /* 238 | * gets the shared link's metadata 239 | */ 240 | public function get_shared_link_metadata($url, $path = null, $link_password = null) { 241 | $endpoint = "https://api.dropboxapi.com/2/sharing/get_shared_link_metadata"; 242 | $headers = array( 243 | "Content-Type: application/json" 244 | ); 245 | $data_array = array("url" => $url); 246 | if (is_null($path) == FALSE) { 247 | array_push($data_array, "path => $path"); 248 | } 249 | if (is_null($link_password) == FALSE) { 250 | $data_array["link_password"] = $link_password; 251 | } 252 | $postdata = json_encode($data_array); 253 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 254 | if (isset($returnData["error"])) { 255 | return $returnData["error_summary"]; 256 | } 257 | else { 258 | return $returnData; 259 | } 260 | } 261 | 262 | /* DEPRECATED BY /list_shared_links*/ 263 | public function get_shared_links($path = "") { 264 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_shared_links"; 265 | $headers = array( 266 | "Content-Type: application/json" 267 | ); 268 | $postdata = json_encode(array( "path" => $path)); 269 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 270 | if (isset($returnData["error"])) { 271 | return $returnData["error_summary"]; 272 | } 273 | else { 274 | return $returnData; 275 | } 276 | } 277 | 278 | public function list_file_members($file, $include_inherited = true, $limit = 100, $actions = array()) { 279 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_file_members"; 280 | $headers = array( 281 | "Content-Type: application/json" 282 | ); 283 | $postdata = json_encode(array( "file" => $file, "include_inherited" => $include_inherited, "limit" => $limit, "actions" => $actions )); 284 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 285 | if (isset($returnData["error"])) { 286 | return $returnData["error_summary"]; 287 | } 288 | else { 289 | return $returnData; 290 | } 291 | } 292 | 293 | public function list_file_members_batch($files, $limit = 10) { 294 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_file_members/batch"; 295 | $headers = array( 296 | "Content-Type: application/json" 297 | ); 298 | $postdata = json_encode(array( "file" => $files, "limit" => $limit )); 299 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 300 | if (isset($returnData["error"])) { 301 | return $returnData["error_summary"]; 302 | } 303 | else { 304 | return $returnData; 305 | } 306 | } 307 | 308 | public function list_file_members_continue($cursor) { 309 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_file_members/continue"; 310 | $headers = array( 311 | "Content-Type: application/json" 312 | ); 313 | $postdata = json_encode(array( "cursor" => $cursor )); 314 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 315 | if (isset($returnData["error"])) { 316 | return $returnData["error_summary"]; 317 | } 318 | else { 319 | return $returnData; 320 | } 321 | } 322 | 323 | public function list_folder_members($shared_folder_id, $limit = 1000, $actions = array()) { 324 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_folder_members"; 325 | $headers = array( 326 | "Content-Type: application/json" 327 | ); 328 | $postdata = json_encode(array( "shared_folder_id" => $shared_folder_id, "limit" => $limit, "actions" => $actions)); 329 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 330 | if (isset($returnData["error"])) { 331 | return $returnData["error_summary"]; 332 | } 333 | else { 334 | return $returnData; 335 | } 336 | } 337 | 338 | public function list_folder_members_continue($cursor) { 339 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_folder_members/continue"; 340 | $headers = array( 341 | "Content-Type: application/json" 342 | ); 343 | $postdata = json_encode(array( "cursor" => $cursor )); 344 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 345 | if (isset($returnData["error"])) { 346 | return $returnData["error_summary"]; 347 | } 348 | else { 349 | return $returnData; 350 | } 351 | } 352 | 353 | public function list_folders($limit = 100, $actions = array()) { 354 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_folders"; 355 | $headers = array( 356 | "Content-Type: application/json" 357 | ); 358 | $postdata = json_encode(array( "limit" => $limit, "actions" => $actions)); 359 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 360 | if (isset($returnData["error"])) { 361 | return $returnData["error_summary"]; 362 | } 363 | else { 364 | return $returnData; 365 | } 366 | } 367 | 368 | public function list_folders_continue($cursor) { 369 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_folders/continue"; 370 | $headers = array( 371 | "Content-Type: application/json" 372 | ); 373 | $postdata = json_encode(array( "cursor" => $cursor )); 374 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 375 | if (isset($returnData["error"])) { 376 | return $returnData["error_summary"]; 377 | } 378 | else { 379 | return $returnData; 380 | } 381 | } 382 | 383 | public function list_mountable_folders($limit = 100, $actions = array()) { 384 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_mountable_folders"; 385 | $headers = array( 386 | "Content-Type: application/json" 387 | ); 388 | $postdata = json_encode(array( "limit" => $limit, "actions" => $actions)); 389 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 390 | if (isset($returnData["error"])) { 391 | return $returnData["error_summary"]; 392 | } 393 | else { 394 | return $returnData; 395 | } 396 | } 397 | 398 | public function list_mountable_folders_continue($cursor) { 399 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_mountable_folders/continue"; 400 | $headers = array( 401 | "Content-Type: application/json" 402 | ); 403 | $postdata = json_encode(array( "cursor" => $cursor )); 404 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 405 | if (isset($returnData["error"])) { 406 | return $returnData["error_summary"]; 407 | } 408 | else { 409 | return $returnData; 410 | } 411 | } 412 | 413 | public function list_received_files($limit = 100, $actions = array()) { 414 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_received_files"; 415 | $headers = array( 416 | "Content-Type: application/json" 417 | ); 418 | $postdata = json_encode(array( "limit" => $limit, "actions" => $actions)); 419 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 420 | if (isset($returnData["error"])) { 421 | return $returnData["error_summary"]; 422 | } 423 | else { 424 | return $returnData; 425 | } 426 | } 427 | 428 | public function list_received_files_continue($cursor) { 429 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_received_files/continue"; 430 | $headers = array( 431 | "Content-Type: application/json" 432 | ); 433 | $postdata = json_encode(array( "cursor" => $cursor )); 434 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 435 | if (isset($returnData["error"])) { 436 | return $returnData["error_summary"]; 437 | } 438 | else { 439 | return $returnData; 440 | } 441 | } 442 | 443 | public function list_shared_links($cursor) { 444 | $endpoint = "https://api.dropboxapi.com/2/sharing/list_shared_links"; 445 | $headers = array( 446 | "Content-Type: application/json" 447 | ); 448 | $postdata = json_encode(array( "cursor" => $cursor )); 449 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 450 | if (isset($returnData["error"])) { 451 | return $returnData["error_summary"]; 452 | } 453 | else { 454 | return $returnData; 455 | } 456 | } 457 | 458 | public function modify_shared_link_settings($url, $settings, $remove_expiration = FALSE) { 459 | $endpoint = "https://api.dropboxapi.com/2/sharing/modify_shared_link_settings"; 460 | $headers = array( 461 | "Content-Type: application/json" 462 | ); 463 | $postdata = json_encode(array( "url" => $url, "settings" => $settings, "remove_expiration" => $remove_expiration )); 464 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 465 | if (isset($returnData["error"])) { 466 | return $returnData["error_summary"]; 467 | } 468 | else { 469 | return $returnData; 470 | } 471 | } 472 | 473 | public function mount_folder($shared_folder_id) { 474 | $endpoint = "https://api.dropboxapi.com/2/sharing/mount_folder"; 475 | $headers = array( 476 | "Content-Type: application/json" 477 | ); 478 | $postdata = json_encode(array( "shared_folder_id" => $shared_folder_id )); 479 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 480 | if (isset($returnData["error"])) { 481 | return $returnData["error_summary"]; 482 | } 483 | else { 484 | return $returnData; 485 | } 486 | } 487 | 488 | public function relinquish_file_membership($file) { 489 | $endpoint = "https://api.dropboxapi.com/2/sharing/relinquish_file_membership"; 490 | $headers = array( 491 | "Content-Type: application/json" 492 | ); 493 | $postdata = json_encode(array( "file" => $file )); 494 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 495 | if (isset($returnData["error"])) { 496 | return $returnData["error_summary"]; 497 | } 498 | else { 499 | return $returnData; 500 | } 501 | } 502 | 503 | public function relinquish_folder_membership($shared_folder_id, $leave_a_copy = FALSE) { 504 | $endpoint = "https://api.dropboxapi.com/2/sharing/relinquish_folder_membership"; 505 | $headers = array( 506 | "Content-Type: application/json" 507 | ); 508 | $postdata = json_encode(array( "shared_folder_id" => $shared_folder_id, "leave_a_copy" => $leave_a_copy )); 509 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 510 | if (isset($returnData["error"])) { 511 | return $returnData["error_summary"]; 512 | } 513 | else { 514 | return $returnData; 515 | } 516 | } 517 | 518 | /* 519 | * Identical to remove_file_member_2 but with less information returned 520 | * @param member: contains an email/dropbox_id and/or a tag specifying it 521 | */ 522 | public function remove_file_member($file, $member) { 523 | $endpoint = "https://api.dropboxapi.com/2/sharing/remove_file_member"; 524 | $headers = array( 525 | "Content-Type: application/json" 526 | ); 527 | $postdata = json_encode(array( "file" => $file, "member" => $member )); 528 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 529 | if (isset($returnData["error"])) { 530 | return $returnData["error_summary"]; 531 | } 532 | else { 533 | return $returnData; 534 | } 535 | } 536 | 537 | /* 538 | * DEPRECATED BY /remove_file_member_2 539 | * removes a specified member from the file 540 | * @param member: contains an email/dropbox_id and/or a tag specifying it 541 | */ 542 | public function remove_file_member_2($file, $member) { 543 | $endpoint = "https://api.dropboxapi.com/2/sharing/remove_file_member_2"; 544 | $headers = array( 545 | "Content-Type: application/json" 546 | ); 547 | $postdata = json_encode(array( "file" => $file, "member" => $member )); 548 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 549 | if (isset($returnData["error"])) { 550 | return $returnData["error_summary"]; 551 | } 552 | else { 553 | return $returnData; 554 | } 555 | } 556 | 557 | /* 558 | * removes a specified member from the folder 559 | * @param member: contains an email/dropbox_id and/or a tag specifying it 560 | */ 561 | public function remove_folder_member($shared_folder_id, $member, $leave_a_copy = FALSE) { 562 | $endpoint = "https://api.dropboxapi.com/2/sharing/remove_folder_member"; 563 | $headers = array( 564 | "Content-Type: application/json" 565 | ); 566 | $postdata = json_encode(array( "shared_folder_id" => $shared_folder_id, "member" => $member, "leave_a_copy" => $leave_a_copy )); 567 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 568 | if (isset($returnData["error"])) { 569 | return $returnData["error_summary"]; 570 | } 571 | else { 572 | return $returnData; 573 | } 574 | } 575 | 576 | public function revoke_shared_link($url) { 577 | $endpoint = "https://api.dropboxapi.com/2/sharing/revoke_shared_link"; 578 | $headers = array( 579 | "Content-Type: application/json" 580 | ); 581 | $postdata = json_encode(array( "url" => $url )); 582 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 583 | if (isset($returnData["error"])) { 584 | return $returnData["error_summary"]; 585 | } 586 | else { 587 | return $returnData; 588 | } 589 | } 590 | 591 | public function share_folder($path, $force_async = FALSE, $acl_update_policy = "editors", $member_policy = "team", $shared_link_policy = "members", $viewer_info_policy = "enabled", $actions = array(), $link_settings = array()) { 592 | $endpoint = "https://api.dropboxapi.com/2/sharing/share_folder"; 593 | $headers = array( 594 | "Content-Type: application/json" 595 | ); 596 | $postdata = json_encode(array( "path" => $path, "force_async" => $force_async, "acl_update_policy" => $acl_update_policy, "member_policy" => $member_policy, "shared_link_policy" => $shared_link_policy, "view_info_policy" => $viewer_info_policy, "actions" => $actions, "link_settings" => $link_settings)); 597 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 598 | if (isset($returnData["error"])) { 599 | return $returnData["error_summary"]; 600 | } 601 | else { 602 | return $returnData; 603 | } 604 | } 605 | 606 | public function transfer_folder($shared_folder_id, $to_dropbox_id) { 607 | $endpoint = "https://api.dropboxapi.com/2/sharing/transfer_folder"; 608 | $headers = array( 609 | "Content-Type: application/json" 610 | ); 611 | $postdata = json_encode(array( "shared_folder_id" => $shared_folder_id, "to_dropbox_id" => $to_dropbox_id )); 612 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 613 | if (isset($returnData["error"])) { 614 | return $returnData["error_summary"]; 615 | } 616 | else { 617 | return $returnData; 618 | } 619 | } 620 | 621 | public function unmount_folder($shared_folder_id) { 622 | $endpoint = "https://api.dropboxapi.com/2/sharing/unmount_folder"; 623 | $headers = array( 624 | "Content-Type: application/json" 625 | ); 626 | $postdata = json_encode(array( "shared_folder_id" => $shared_folder_id )); 627 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 628 | if (isset($returnData["error"])) { 629 | return $returnData["error_summary"]; 630 | } 631 | else { 632 | return $returnData; 633 | } 634 | } 635 | 636 | public function unshare_file($file) { 637 | $endpoint = "https://api.dropboxapi.com/2/sharing/unshare_file"; 638 | $headers = array( 639 | "Content-Type: application/json" 640 | ); 641 | $postdata = json_encode(array( "file" => $file )); 642 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 643 | if (isset($returnData["error"])) { 644 | return $returnData["error_summary"]; 645 | } 646 | else { 647 | return $returnData; 648 | } 649 | } 650 | 651 | public function unshare_folder($shared_folder_id, $leave_a_copy = FALSE) { 652 | $endpoint = "https://api.dropboxapi.com/2/sharing/unshare_folder"; 653 | $headers = array( 654 | "Content-Type: application/json" 655 | ); 656 | $postdata = json_encode(array( "shared_folder_id" => $shared_folder_id, "leave_a_copy" => $leave_a_copy )); 657 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 658 | if (isset($returnData["error"])) { 659 | return $returnData["error_summary"]; 660 | } 661 | else { 662 | return $returnData; 663 | } 664 | } 665 | 666 | public function update_file_member($file, $member, $access_level) { 667 | $endpoint = "https://api.dropboxapi.com/2/sharing/update_file_member"; 668 | $headers = array( 669 | "Content-Type: application/json" 670 | ); 671 | $postdata = json_encode(array( "file" => $file, "member" => $member, "access_level" => $access_level )); 672 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 673 | if (isset($returnData["error"])) { 674 | return $returnData["error_summary"]; 675 | } 676 | else { 677 | return $returnData; 678 | } 679 | } 680 | 681 | public function update_folder_member($shared_folder_id, $member, $access_level) { 682 | $endpoint = "https://api.dropboxapi.com/2/sharing/update_folder_member"; 683 | $headers = array( 684 | "Content-Type: application/json" 685 | ); 686 | $postdata = json_encode(array( "shared_folder_id" => $shared_folder_id, "member" => $member, "access_level" => $access_level )); 687 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 688 | if (isset($returnData["error"])) { 689 | return $returnData["error_summary"]; 690 | } 691 | else { 692 | return $returnData; 693 | } 694 | } 695 | 696 | public function update_folder_policy($shared_folder_id, $member_policy = "team", $acl_update_policy = "owner", $viewer_info_policy = "disabled", $shared_link_policy = "members", $link_settings = array(), $actions = array()) { 697 | $endpoint = "https://api.dropboxapi.com/2/sharing/update_folder_policy"; 698 | $headers = array( 699 | "Content-Type: application/json" 700 | ); 701 | $postdata = json_encode(array( "shared_folder_id" => $shared_folder_id, "member_policy" => $member_policy, "acl_update_policy" => $acl_update_policy, "viewer_info_policy" => $viewer_info_policy, "shared_link_policy" => $shared_link_policy, "link_settings" => $link_settings, "actions" => $actions )); 702 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 703 | if (isset($returnData["error"])) { 704 | return $returnData["error_summary"]; 705 | } 706 | else { 707 | return $returnData; 708 | } 709 | } 710 | 711 | // * * ***** **** **** 712 | // ** ** * * * 713 | // * * * * *** * 714 | // * * * * * 715 | // * * ***** **** **** * 716 | 717 | public function __construct() { 718 | } 719 | 720 | } 721 | 722 | ?> -------------------------------------------------------------------------------- /sdk/Dropbox/Users.php: -------------------------------------------------------------------------------- 1 | $account_id )); 19 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 20 | if (isset($returnData["error"])) { 21 | return $returnData["error_summary"]; 22 | } 23 | else { 24 | return $returnData; 25 | } 26 | } 27 | 28 | public function get_account_batch($account_ids) { 29 | $endpoint = "https://api.dropboxapi.com/2/users/get_account/batch"; 30 | $headers = array( 31 | "Content-Type: application/json" 32 | ); 33 | $postdata = json_encode(array( "account_ids" => $account_ids )); 34 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 35 | if (isset($returnData["error"])) { 36 | return $returnData["error_summary"]; 37 | } 38 | else { 39 | return $returnData; 40 | } 41 | } 42 | 43 | public function get_current_account() { 44 | $endpoint = "https://api.dropboxapi.com/2/users/get_current_account"; 45 | $headers = array( 46 | "Content-Type: application/json" 47 | ); 48 | $postdata = "null"; 49 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 50 | return $returnData; 51 | } 52 | 53 | public function get_space_usage() { 54 | $endpoint = "https://api.dropboxapi.com/2/users/get_space_usage"; 55 | $headers = array( 56 | "Content-Type: application/json" 57 | ); 58 | $postdata = "null"; 59 | $returnData = Dropbox::postRequest($endpoint, $headers, $postdata); 60 | return $returnData; 61 | } 62 | 63 | // * * ***** **** **** 64 | // ** ** * * * 65 | // * * * * *** * 66 | // * * * * * 67 | // * * ***** **** **** * 68 | 69 | public function __construct() { 70 | } 71 | } 72 | 73 | ?> --------------------------------------------------------------------------------