Evert Pot is a web architect, blogger and open-source developer. Evert specialized in the HTTP protocol and the LAMP stack. His interests lie in making systems and development teams scale. Evert is a DZone MVB and is not an employee of DZone and has posted 8 posts at DZone. You can read more from them at their website. View Full User Profile

Dropbox client library for PHP

09.13.2011
| 4917 views |
  • submit to reddit
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:

    pear channel-discover pear.sabredav.org
    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.

    <?php
     
    /* Please supply your own consumer key and consumer secret */
    $consumerKey = '';
    $consumerSecret = '';
     
    include 'Dropbox/autoload.php';
     
    session_start();
     
    $dropbox = new Dropbox_API($consumerKey, $consumerSecret);
     
    /* Display account information */
    var_dump($dropbox->getAccountInfo());
     
    /* Upload itself */
    $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)

References
Published at DZone with permission of Evert Pot, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Nabeel Manara replied on Fri, 2012/01/27 - 11:40am

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 ...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.