cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We want to hear from you. What do you use Dropbox for?
Close

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted

Cron job to upload files from server to Dropbox

Helpful | Level 5

I've been able to create a PHP app that allows me to upload files through the API into dropbox.  It works great; however, the problem is, the first time you access it, you have to authenticate to get the token and then it's able to work.  This all requires interaction of a user to do so.  My goal is to create a cron job that will run hourly and copy any new files from a folder into my dropbox in order to have a backup copy of the files.  Is this possible?  If so, can anyone point me in the direction of an example?

Thank you!

1 Accepted Solution

Accepted Solutions
Highlighted

Re: Cron job to upload files from server to Dropbox

Dropboxer
Dropboxer

The token you get back after authorizing the app is called an "access token", and is specific to that particular app-user pair. Access tokens for your app don't expire by default, so once the app receives one, you can have it store and re-use it, so it can make API calls in the future for that user without further manual user intervention. 

So, you'll probably want to have your app do something like this each time it runs:

  • check if it has an access token stored already
    • if it does, use that existing access token
    • if it doesn't, send the user through the app authorization flow to get an access token, and store the resulting access token
  • call the API to upload the file(s)

I don't have a sample of this to share in PHP though. Exactly what mechanism you use to store the access token will depend on what platform and libraries you're using. Keep in mind that the access token does enable access to the account, so you should store it securely.

View solution in original post

4 Replies 4
Highlighted

Re: Cron job to upload files from server to Dropbox

Dropboxer
Dropboxer

The token you get back after authorizing the app is called an "access token", and is specific to that particular app-user pair. Access tokens for your app don't expire by default, so once the app receives one, you can have it store and re-use it, so it can make API calls in the future for that user without further manual user intervention. 

So, you'll probably want to have your app do something like this each time it runs:

  • check if it has an access token stored already
    • if it does, use that existing access token
    • if it doesn't, send the user through the app authorization flow to get an access token, and store the resulting access token
  • call the API to upload the file(s)

I don't have a sample of this to share in PHP though. Exactly what mechanism you use to store the access token will depend on what platform and libraries you're using. Keep in mind that the access token does enable access to the account, so you should store it securely.

View solution in original post

Highlighted

Re: Cron job to upload files from server to Dropbox

Helpful | Level 5

I wondered if that might be the case.  Thank you so much for your help!

Highlighted

Re: Cron job to upload files from server to Dropbox

New member | Level 2
New member | Level 2

What if you are not acting on behalf of the users? For example, in my case, we are just pushing files to Dropbox as part of an app-sync/integration. Do we need to provision an API user and build a UI around re-authenticating them?

Highlighted

Re: Cron job to upload files from server to Dropbox

Dropboxer
Dropboxer

@caseyprovost In order to upload to Dropbox via the Dropbox API, you need to upload to some particular user account. If you don't need to connect to arbitrary end-user accounts, and are just connecting to your own account, for instance, you don't need to build the app authorization flow and UI. You can just get your own access token once and use that.

Polls
Do you know how to organize your files and folders?
<b>We have created a guide on folder best practice, so you can get organized now <a href="https://www.dropboxforum.com/t5/Business-Tips-tricks/Folder-structure-best-practice/m-p/428456#M39"><u>check it out here</u></a>.</b>

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?