Use of dropbox with core APIs, but avoiding login

2019-04-15 01:27发布

问题:

I want to use Dropbox for my file share application, using Core Dropbox APIs. I am using OAuth 2.0 APIs for authentication (Implicit Grant Method). The issue is, In order to obtain the access token, I need to be logged-in to dropbox account or it redirects me to Dropbox login page. I don't want my users to enter the login crediantials.

Is there any way to avoid login process, and directly get access token?? Or Alternatively can I do login using some login api in backend, without user iteraction??

here I am considering a single Dropbox account, whose all necessary crediantials are with me.

Thanks.

回答1:

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.



回答2:

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.



回答3:

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.



回答4:

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.