Python Forum

Full Version: how to connect and read fiels from dropbox using Python3.6?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi ALl,

Has anyone connected with the dropbox using Python3.6?

I am trying to first connect with the drobox and then I need to read some csv files from there.
For that I have written a helper class which have functions-connect,read etc.

I have read the api v2 doc api v2 drobox doc

But couldn't find the way to achieve my goal.Below is my code snippet for this but it is not complete and need your help-

class DropBoxHelper(object):
    def connect_to_dropbox(self):
        config = configparser.ConfigParser()
        config.read(os.path.abspath(os.pardir) + '/config.ini')
        app_key = config['DROPBOX']['KEY']
        app_secret = config['DROPBOX']['SECRET']
        access_type = "dropbox"
        session = dropbox.Dropbox(app_key)

if __name__ == '__main__':
    DropBoxHelper.connect_to_dropbox(object)
Can anyone please look into this and share me how to complete this?
Since docs are not clear to me, I am sharing my solution so that it may help others also-
In dropbox's app console we need to generate access token which can be used as below:
    def connect_to_dropbox(self):
        config = configparser.ConfigParser()
        config.read(os.path.abspath(os.pardir) + '/config.ini')
        access_token = config['DROPBOX']['ACCESS_TOKEN']
        dbx = dropbox.Dropbox(access_token)
        return dbx
In above code I am storing the dropbox credentials in config.ini file and passing it to the Dropbox() method.
With this way I am able to connect with the dropbox successfully.
(Jul-11-2018, 05:20 AM)PrateekG Wrote: [ -> ]Since docs are not clear
That is pretty much your opinion. Did you read

https://www.dropbox.com/developers/docum...n#tutorial

Quote:Link an account

In order to make calls to the API, you'll need an instance of the Dropbox object. To instantiate, pass in the access token for the account you want to link. (Tip: You can generate an access token for your own account through the App Console).
dbx = dropbox.Dropbox('YOUR_ACCESS_TOKEN')
Test it out to make sure you've linked the right account:
dbx.users_get_current_account()
(Jul-11-2018, 06:57 AM)buran Wrote: [ -> ]
(Jul-11-2018, 05:20 AM)PrateekG Wrote: [ -> ]Since docs are not clear
That is pretty much your opinion. Did you read

https://www.dropbox.com/developers/docum...n#tutorial

Quote:Link an account

In order to make calls to the API, you'll need an instance of the Dropbox object. To instantiate, pass in the access token for the account you want to link. (Tip: You can generate an access token for your own account through the App Console).
dbx = dropbox.Dropbox('YOUR_ACCESS_TOKEN')
Test it out to make sure you've linked the right account:
dbx.users_get_current_account()

Yes Buran, it was my opinion and I hope you will come forward very first next time to help others!