Use of dropbox with core APIs, but avoiding login page

允我心安 提交于 2019-12-04 21:40:10

Yes you can do this.

Do the following:

Go to https://www.dropbox.com/developers Click on "App Console" Click on "Create App" Select "Dropbox API app" Select "Files and Datastores" for the type of data. Answer the rest of the questions with your own preference for access

Here's the bit that you need. Once the app is setup, in the App Console, click on the app. On the main page for the app, in the OAUTH2 section, there's a button that says "Generate Access Token".

Click on this button, and it will generate a non-expiring access token that you can copy/paste and use in your app to give you access without having to do the Oauth2 authentication dance.

Here's an example of using the access token with curl to list files in a folder (and get other meta data).

curl https://api.dropbox.com/1/metadata/dropbox/YourFolder -H "Authorization:Bearer XYZ123"

Where XYZ123 is your access token you generated from the app console of the app.

As long as you include the Authorization: Bearer in the header of your request, you can use all the API calls in the Core API withouth having to supply an app ID, secret, or do the oauth2 authentication dance.

Hans Z.

Since you want to use your Dropbox account to store the files, there's no reason to bother other/your users with a login: just obtain an access_token for your client in the regular way (which requires you to login to Dropbox) store it in your application and use that access_token in your calls to the Dropbox APIs. Dropbox' access token never expires according to Dropbox Access Token Expiry so that should be all you need.

As you have probably seen in the core api documentation, Dropbox does not offer this feature.

You can automate the process by simulating the user interaction with the website, though. This can be done with the requests module. I developed a solution for my project:

https://github.com/joe42/CloudFusion/blob/master/cloudfusion/store/dropbox/dropbox_store.py#L214

Maybe this can be done more easily using a solution like PhantomJS, though I did not know about it at that time.

Putting probable solution to my own question here: The main issue here was about re-generation of the Access Token at some intervals, that too without any user interaction, a backend stuff. After going through Dropbox APIs, I concluded there is no API exposed for re-generation of Access Token automatedly. But Google Drive do offer Service Account, which do not require user interaction.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!