You are here

public function BackupMigrateDropboxAPI::list_folder in Backup and Migrate Dropbox 7.2

Same name and namespace in other branches
  1. 7.3 backup_migrate_dropbox.dropbox_api.inc \BackupMigrateDropboxAPI::list_folder()

Returns the contents of a Dropbox folder.

{@link https://www.dropbox.com/developers/documentation/http/documentation#file... Dropbox API /list_folder}

Parameters

string $folder:

Return value

object[] A list of file metadata of the files in the folder.

Throws

\RuntimeException

File

./backup_migrate_dropbox.dropbox_api.inc, line 28
backup_migrate_dropbox.api.inc

Class

BackupMigrateDropboxAPI
@file backup_migrate_dropbox.api.inc

Code

public function list_folder($folder) {

  // Note, I once got this message: Dropbox error: Error in call to API
  // function "files/list_folder": request body: path: Specify the root folder
  // as an empty string rather than as "/". So we'handle that case here.
  if ($folder === '/') {
    $folder = '';
  }

  // Simple listing: using Dropbox defaults:
  // - Not recursive.
  // - No deleted files.
  // - Include mounted files (the app folder is a mounted folder).
  $parameters = array(
    'path' => $folder,
    'include_non_downloadable_files' => TRUE,
  );
  $response = $this
    ->sendMessage('api', 'files/list_folder', $parameters);
  $files = $response->entries;
  while ($response->has_more) {
    $parameters = [
      'cursor' => $response->cursor,
    ];
    $response = $this
      ->sendMessage('api', 'files/list_folder/continue', $parameters);
    $files = array_merge($files, $response->entries);
  }
  return $files;
}