



I probably should have made it so you could pass a file to the method too, but that'll have to wait until version 2. I also created and upload_file method to allow easy uploading of files. For example, you can get your account information or a bunch of metadata about any folder in your Dropbox. Once you're connected, the client is instantiated and you can extract all kinds of information about your Dropbox. I tried to find a way to cache the request token, but I always got an error about my token being expired, so this script will always pop up a browser window asking you to "Allow" your application access to your Dropbox. Then I use configobj to extract that information into a Python dictionary. I put my key and secret into a config file that looks something like this: Path = os.path.join(self.path, self.filename) Upload a file to dropbox, returns file info dict Return a dictionary of information about a folderįolder_metadata = (folder)įolder_metadata = ("/") Returns the account information, such as user's display name, Self.client = (session)ĭef download_file(self, filename=None, outDir=None):ĭownload either the file passed to the class or the file passedį, metadata = _file_and_metadata("/" + fname) Please make sure this application is allowed before continuing."Īccess_token = session.obtain_access_token(request_token) Url = session.build_authorize_url(request_token) Request_token = session.obtain_request_token() Print "ERROR: config.ini not found! Exiting!" Self.base_path = os.path.dirname(os.path.abspath(_file_))Ĭonfig_path = os.path.join(self.base_path, "config.ini") Here's what I came up with:ĭropbox object that can access your dropbox folder,Īs well as download and upload files to dropboxĭef _init_(self, filename=None, path='/'): Now we're ready to start writing some code.

Once you have that, you'll need to name your application and choose your access level. You will also need to sign up for a key and secret. You'll need to download their dropbox module to follow along or use "pip install dropbox" to install it. I ended up using their tutorial to design a simple class for accessing my Dropbox. Yesterday, I stumbled on to Dropbox's Python API.
