PHP code example of zanderwar / lumen-dropbox

1. Go to this page and download the library: Download zanderwar/lumen-dropbox library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zanderwar / lumen-dropbox example snippets




return [

    /*
    * set the client id
    */
    'clientId' => env('DROPBOX_CLIENT_ID'),

    /*
    * set the client secret
    */
    'clientSecret' => env('DROPBOX_SECRET_ID'),

    /*
    * Set the url to trigger the oauth process this url should call return Dropbox::connect();
    */
    'redirectUri' => env('DROPBOX_OAUTH_URL'),

    /*
    * Set the url to redirecto once authenticated;
    */
    'landingUri' => env('DROPBOX_LANDING_URL', '/'),

    /**
     * Set access token, when set will bypass the oauth2 process
     */
    'accessToken' => env('DROPBOX_ACCESS_TOKEN', ''),

    /**
     * Set access type, options are offline and online
     * Offline - will return a short-lived access_token and a long-lived refresh_token that can be used to request a new short-lived access token as long as a user's approval remains valid.
     *
     * Online - will return a short-lived access_token
     */
    'accessType' => env('DROPBOX_ACCESS_TYPE', 'offline'),

    /*
    set the scopes to be used
    */
    'scopes' => 'account_info.read files.metadata.write files.metadata.read files.content.write files.content.read',
];

$router->group([/** Middleware etc */], function(\Laravel\Lumen\Routing\Router $router) {
    $router->get('/dropbox/connect', function() {
        if (! request()->has('code')) {
            // user is heading to dropbox
            $arbitraryData = ['hello' => 'world'];
            return \Zanderwar\Dropbox\Dropbox::connect(json_encode($arbitraryData));     
        }
        
        // user is returning from dropbox
        $state = request()->input('state');
        
        if (! $state) {
            throw new \RuntimeException('The state parameter is missing from the request.');
        }
        
        // do stuff with $state...
        // e.g. Passport::actingAs(Decrypt::json($state)->user_id)
        
        // finalise the account internally, by calling the connect method again. This will fetch
        // an access/refresh token from dropbox. This behaviour is only exhibited when the `code`
        // query param is in the URL.
        return \Zanderwar\Dropbox\Dropbox::connect();
    });

    $router->get('/dropbox/disconnect', function() {
        return Dropbox::disconnect('path/to/redirect/to');
    });

});

Dropbox::get($endpoint, $array = [], $headers = [], $useToken = true)
Dropbox::post($endpoint, $array = [], $headers = [], $useToken = true)
Dropbox::put($endpoint, $array = [], $headers = [], $useToken = true)
Dropbox::patch($endpoint, $array = [], $headers = [], $useToken = true)
Dropbox::delete($endpoint, $array = [], $headers = [], $useToken = true)

Dropbox::post('users/get_current_account')

app()->middleware([
    'dropbox.auth' => \Zanderwar\Dropbox\Http\Middleware\DropboxAuthMiddleware::class
]);

$router->group(['middleware' => ['dropbox.auth']], function (\Laravel\Lumen\Routing\Router $router) {
    // your routes
});

use Zanderwar\Dropbox\Models\DropboxToken;

use Zanderwar\Dropbox\Facades\Dropbox;

Dropbox::files()->listContents($path = '')

Dropbox::files()->listContentsContinue($cursor = '')

Dropbox::files()->delete($path)

Dropbox::files()->createFolder($path)

Dropbox::files()->search($query)

Dropbox::files()->upload($path, $file)

Dropbox::files()->download($path)

Dropbox::files()->move($fromPath, $toPath, $autoRename = false, $allowOwnershipTransfer = false);

php artisan vendor:publish --provider="Zanderwar\Dropbox\DropboxServiceProvider" --tag="config"

php artisan migrate