phpdropboxdropbox-apidropbox-php

Dropbox file upload automatically using php


I'm playing with Dropbox API for PHP, and I would like know the correct way to upload files automatically without command line.

Now my process is:

  1. php -f upload.php
  2. Copy long url on browser
  3. Click allow button
  4. Copy the token
  5. paste the token on console and done.

My plan is do an automated backup of some JSON files on my Dropbox.

Is there other way to make that without console? and copying tokens and simple solution?

EDIT When I try to hardcode it, the output it´s ->

Fatal error: Uncaught exception 'Dropbox\Exception_BadRequest' with message 'HTTP status 400
{"error_description": "code has already been used", "error": "invalid_grant"}'

EDIT 2*

The access token output

dusIlAq36pkAAAAAAAAHQ6daX9hwt-3wUL240gUUjIOYrscX2OYOkCyj8ZghUgG2

I set it as

$authCode = 'dusIlAq36pkAAAABBBBBAAAHQ6daX9hwt-3wUL240gUUjIOYrscX2OYOkCyj8ZghUgG2';

Here Drop MSG

 ...Fatal error: Uncaught exception 'Dropbox\Exception_BadRequest' with message 'HTTP status 400
{"error_description": "code doesn't exist or has expired",

Solution

  • The user only has to authorize your app once. After that, you can just keep reusing that access token. (You can hardcode it in your script.)

    EDIT

    From https://www.dropbox.com/developers/core/start/php:

    Finally, call finish to convert the authorization code into an access token.

    list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
    print "Access Token: " . $accessToken . "\n";
    

    The access token is all you'll need to make API requests on behalf of this user, so you should store it away for safe-keeping (even though we don't for this tutorial). By storing the access token, you won't need to go through these steps again unless the user reinstalls your app or revokes access via the Dropbox website.