Skip to content
A Dropbox API Plugin for CakePHP 2.x
Find file
Latest commit 119d619 Dec 13, 2012 @shama Merge pull request #4 from thepeg/master
Fix file download API

Cakebox: A Dropbox API Plugin for CakePHP 2


PHP5+, CakePHP 2+, Dropbox account (w/ API credentials)


  1. Sign up for a Dropbox app.
  2. Extract the contents of this repo into app/Plugin/Dropbox/ or use git clone or git submodule in your app/Plugin folder:
git clone git:// Dropbox
  1. Enable the plugin in your app/Config/bootstrap.php with:
// OR
  1. Copy the following lines into app/Config/database.php and add your consumer key and secret:
public $dropbox = array(
  'datasource' => 'Dropbox.DropboxSource',
  'consumer_key' => 'CONSUMER KEY HERE',
  'consumer_secret' => 'CONSUMER SECRET HERE',


The easiest way to use this plugin is to include the Dropbox.DropboxApi component in your controller:

public $components = array('Dropbox.DropboxApi');

Authorize with Dropbox

Before you can use the Dropbox API you need to authorize a Dropbox account to use your app. This is done through OAuth and the included component can help. Add a new method to your controller and call the authorize() method:

public function authorize_with_dropbox() {

This will take you through the redirect steps to authorize your Dropbox account with your app via OAuth.

By default the tokens will be only saved in a session. You'll want to save them longer. The recommended way is to use the AuthComponent by including Auth in your controller's components. Then create the fields dropbox_token and dropbox_token_secret in your users table. Then the DropboxApi component will automatically save the tokens for the logged in user.

If you don't want to use the default field names you can set them when including the component:

public $components = array(
  'Dropbox.DropboxApi' => array(
    'fields' => array(
      'dropbox_token' => 'my_token_field',
      'dropbox_token_secret' => 'my_secret_field',

Or if you want to use another Dropbox Model or User Model:

public $components = array(
  'Dropbox.DropboxApi' => array(
    'userModel' => 'Member',
    'dropboxModel' => 'MyDropbox',

Have a look in Controller/Component/DropboxApiComponent.php for all the settings.

The Dropbox API

After you have authorized your app and have your tokens; you're ready to use the Dropbox API:

// Get a list of files from a root Dropbox folder
$files = $this->DropboxApi->ls();

// Get files within a path
$files = $this->DropboxApi->ls('Path/In/Dropbox');

// Limit the amount of files returned
$files = $this->DropboxApi->ls('Path/In/Dropbox', array('file_limit' => 10));

// Alternative syntax
$files = $this->DropboxApi->ls(array(
  'path' => 'Path/In/Dropbox',
  'file_limit' => 10,

Check the Model/Dropbox.php for more methods. All of the Dropbox API methods are available. Check the Dropbox API docs for more info: [].

Your Own Dropbox Model

In order to keep your models fat and controller skinny. You may want to create your own model to handle more complex operations with Dropbox. Create a model in your app/Model/ folder as such:

App::uses('Dropbox', 'Dropbox.Model');
class MyDropbox extends Dropbox {
  public $dropbox_token = 'SET THESE TO YOUR TOKENS';
  public $dropbox_token_secret = 'SET THESE TO YOUR TOKENS';

  public function complex() {
    $info = $this->account_info();
      'from_path' => 'Copy/This/',
      'to_path' => 'To/This/',
    return $this->ls('To/This/');

You can use the Dropbox.Dropbox model anywhere with $Dropbox = ClassRegistry::init('Dropbox.Dropbox');. Just be sure to set the properties dropbox_token and dropbox_token_secret with your authenticated tokens (not your consumer key/secret).


Please report any issues you have with the plugin to the issue tracker on github.



Cakebox is offered under an MIT license.


2012 Kyle Robinson Young,

If you found this release useful please let the author know! Follow on Twitter

Something went wrong with that request. Please try again.