- summary Dropbox_API documentation.
- labels Featured
The Dropbox API class is the main class to interact with the dropbox API. It has all the convenience methods to access and modify dropbox information.
The constructor takes at least 2 arguments:
* $consumerKey * $consumerSecret
You can find these keys on the Dropbox developer site, under 'My applications'.
example:
There are 2 ways to authenticate with Dropbox. Using the regular oauth authentication flow, or simply by providing a username and password.
This is the simple way to authenticate, it works as follows:
This method is a bit more involved, but better for your user because you never need to ask them for a username and password. I can see the Dropbox people actually requiring this authentication method for web-based apps in the future.
By default Dropbox works with 2 different 'roots', the
* Sandbox, which is 1 specific directory assigned for your application * Dropbox, which is the users' entire dropbox directory.
Before 'sandbox' was the default root, but sandbox is disabled for new applications so now 'dropbox' is the default. In most cases you don't have to worry about this.
Using the getAccountInfo you can grab a users account information, such as their quota. Simply call $dropbox->getAccountInfo();
Using getFile you can download a file. At the moment the function returns the entire file's body as a string. This might be fixed in the future once PHP's OAuth extension no longer requires this.
You can override the default root by specifying it as a second argument:
Using putFile you can upload a file. At the moment the function will store the entire file temporarily as a string. This might be fixed in the future once PHP's OAuth extension no longer requires this.
You can specify the file as a local path, or as an open file stream.
Example 1:
Example 2:
You can override the default root by specifying it as a third argument:
Copy makes an exact copy of a file or directory.
Example:
You can override the default root by specifying it as a third argument:
createFolder creates a new, empty, folder.
Example:
You can override the default root by specifying it as a second argument:
delete deletes a file or directory (and all it's contents).
Example:
You can override the default root by specifying it as a second argument:
Move moves a file or directory to a new location:
Example:
You can override the default root by specifying it as a third argument:
getMetadata is used to retrieve information about files, or about the contents of a directory.
Example 1:
The second parameter specifies what you want to retrieve. If you're fetching info about a directory, and it is set to true, the directories contents will be returned. If it's set to 'false', only the directories' information will be returned:
Example 2:
The getThumbnail method works like getFile, except it can be used to retrieve an image's thumbnail.
The first argument specifies the filename, the second specifies the size (small, medium, large).
The optional third argument can be used to change the default root:
The example directory in the package is quite complete, everthing you need to know should be in there. You can also browse the source.