Dropbox client library for PHP

I enjoy using Dropbox. It is a very easy syncing and backup tool, and it works everywhere. A few days ago the developer API was released. After a bit of wrestling with oauth, I completed a client library for PHP, and open sourced it (MIT licensed).

If you want to give it a shot, you first need to sign up for the developer program and get yourself your security tokens. Once that's done, you can install the library using:

  1. pear channel-discover pear.sabredav.org
  2. pear install sabredav/Dropbox-alpha

If that worked, you should be able to start using the API. The following example displays account information and uploads a file.

  1. <?php
  2.  
  3. /* Please supply your own consumer key and consumer secret */
  4. $consumerKey = '';
  5. $consumerSecret = '';
  6.  
  7. include 'Dropbox/autoload.php';
  8.  
  9. session_start();
  10.  
  11. $dropbox = new Dropbox_API($consumerKey, $consumerSecret);
  12.  
  13. /* Display account information */
  14. var_dump($dropbox->getAccountInfo());
  15.  
  16. /* Upload itself */
  17. $dropbox->putFile(basename(__FILE__), __FILE__);

The script needs to be run in a browser, because you will be redirected to Dropbox to authorize access.

I hope people like the library, and if you have any suggestions, feel free to let me know. If you want to contribute, you can head over to the project site on google code.

If you haven't used Dropbox yet and want to try it, consider signing up through this link. If you do so, both you and my girlfriend get an extra 250MB space for free (and she really needs it).


5 Responses to Dropbox client library for PHP

  1. 4922 PHP Dude 2010-07-29 5:58 am

    I am using the dropbox API, It redirects to the dropbox site, but I don't want it to do that I want to do the authentication in my site any tricks I can use ? thanks in advance

  2. 4934 Evert 2010-07-29 4:28 pm

    Hi PHP Dude,

    The next version (0.4) will allow you to do this. If you can't wait for the release, download the latest source from mercurial.

    Evert

  3. 7155 Shijith 2010-11-17 5:50 am

    Hi Guys,

    I have implemented dropbox php authentication in my site. Its working fine but one query I have, is it possible to authenticate dropbox without use of consumer key and consumer secret, using only username and password ? plz post ur suggestion regarding this ...

    best.

  4. 12180 ChinaBoy 2011-04-22 4:10 pm

    I dont understand how to install the library. Where do I have to type in the commands:

    pear channel-discover pear.sabredav.org
    pear install sabredav/Dropbox-alpha

    ???

  5. 22376 lovrboy 2011-08-23 8:01 am

    ChinaBoy: Gotta use command line. If you are on a mac you can use terminal and ssh to your server. Here is a neat little tutorial http://net.tutsplus.com/tutorials/other/7-simple-and-useful-command-line-tips/

    Everyone else:
    Anyone know the right way to set up HTTP_OAuth manually? Where to put the folder and so on?

Leave a Reply



About

My name is Evert, and I've been writing semi-regularly on this blog since 2006.

I'm currently available for contract work.

more info.

Subscribe

Dropbox

Dropbox is a simple cross-platform online backup and sync application. The first 2GB of space is free, and both you and me get an extra 250MB extra space if you sign up through this link.