-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Dropbox API Library
Category:Contributions::Libraries::Dropbox API Category:Libraries::Dropbox API Category:Library::Dropbox API
Please checkout the github repository for the latest version
https://github.com/jimdoescode/CodeIgniter-Dropbox-API-Library
This documentation expects that you have a reasonable understanding of OAuth and have gotten and API Key and API Secret from Dropbox.
This library will let you interact with the Dropbox API and manipulate the files in a users Dropbox account. OAuth authentication is required prior to using the dropbox methods of the library.
You can get the required access token data via controller methods such as these.
public function request_dropbox()
{
$params['key'] = $this->config->item('dropbox_key');
$params['secret'] = $this->config->item('dropbox_secret');
$this->load->library('dropbox', $params);
$data = $this->dropbox->get_request_token(site_url("welcome/access_dropbox"));
$this->session->set_userdata('token_secret', $data['token_secret']);
redirect($data['redirect']);
}
public function access_dropbox()
{
$params['key'] = $this->config->item('dropbox_key');
$params['secret'] = $this->config->item('dropbox_secret');
$this->load->library('dropbox', $params);
$oauth = $this->dropbox->get_access_token($this->session->userdata('token_secret'));
$this->_store_in_db($oauth['oauth_token']);
$this->_store_in_db($oauth['oauth_token_secret']);
}
Once you have the OAuth token and token secret for a particular user you can then store those with the user and use them for any subsequent calls to the API. They do no expire so you should only need to authenticate a user with OAuth once.
After you have a token and token secret you can now pass those to the library when it is loaded like this.
$params['key'] = $this->config->item('dropbox_key');
$params['secret'] = $this->config->item('dropbox_secret');
$params['access'] = array('oauth_token'=>urlencode($this->_get_from_db()),
'oauth_token_secret'=>urlencode($this->_get_from_db()));
$this->load->library('dropbox', $params);
Now that the library is loaded with the correct credentials you can call any of the methods below.
$this->dropbox->account();
$this->dropbox->thumbnail($destination, $path, $size='small', $format='JPEG', $root='dropbox')
$this->dropbox->get($destination, $path, $root='dropbox')
$this->dropbox->add($dbpath, $filepath, $root='dropbox');
$this->dropbox->metadata($path, $root='dropbox');
$this->dropbox->link($path);
$this->dropbox->copy($from, $to, $root='dropbox');
$this->dropbox->create_folder($path, $root='dropbox');
$this->dropbox->delete($path, $root='dropbox');
$this->dropbox->move($from, $to, $root='dropbox');
For further documentation or if you have any questions you can reach me at my blog
http://jimdoescode.blogspot.com/2011/07/codeigniter-dropbox-api.html
I hope you enjoy this library.