Access dropbox folder on Android

3

Is there any way to access the dropbox folder?

I have the following problem, I am developing a webapp that will work locally on tablets of an event, so for this I am using the AndroPHP app and I would like my apache directory to be a dropbox folder so that I could update all the apps of the tablets, just updating my folder in the dropbox and thus synchronizing with the tablets, does anyone know of any way to do this?

    
asked by anonymous 08.04.2015 / 21:00

1 answer

5

Dropbox has an API for this link

Easy to integrate, I think there will be no problems.

===================================================== =

Let's go then as requested:

================================================

Basic APP Instruction

  • CREATE AN APP WITH DROPBOX
  • Create an APP on DROPBOX link
  • Choose "Dropbox API app" then select "Yes - My application only needs access to files it creates."
  • From a name to the APP and in a row you will be redirected to the APP config screen,
  • set the return url where you will save the authentication token

Ex:

http://localhost/dropboxAPI/end_auth.php 
  • On this same page you will see your APP_KEY and APP_SECRET - which you will use to authenticate the APP.

=========================================================== p>

=========================================================== p>

  • Inside the folder of your APP in this case I used the folder "dropboxAPI /" create a file called "composer.json" put the following code in it

    {
      "require": {
        "dropbox/dropbox-sdk": "1.1.*"
      }
    }
    
    • Enter the folder of your APP by the CMD or terminal already with the file "composer.json" created.

EX:

/var/html/dropboxAPI/

e digite o comando: 

composer install
  • Wait for the package to finish installing.

=========================================================== p>

  • CREATING THE FILES

  • For this example we are creating the following files

    • index.php
    • end_auth.php
    • config.php
  • File below 'config.php'

    <?php
    session_start();
    function pre($arg){
        echo "<pre>";
           print_r($arg);
        echo "</pre>";
    }
    require  "vendor/autoload.php";
    define('DROPBOX_KEY'    , 'sua key');
    define('DROPBOX_SECRET' , 'seu secret');
    define('APP_NAME'       , 'ShowRoomEvent');
    # inicia classe
    $app = new Dropbox\AppInfo(DROPBOX_KEY,DROPBOX_SECRET);
    # metodo token verificacao
    $tokenCsfr = new Dropbox\ArrayEntryStore($_SESSION,'dropbox-auth-csrf-token');
    # pede autenticacao
    $auth  = new Dropbox\WebAuth($app,APP_NAME,'http://localhost/dropboxAPI/end_auth.php',$tokenCsfr);
    
    ?>
    
  • Below is the end_auth.php (or the file you set in the APP URL)

    <?php
    # inicio arquivo end_auth.php
    # RECEBE O TOKEN DO DROPBOX
    require 'config.php';
    list($getToken) = $auth->finish($_GET);
    if( isset($getToken) && !empty($getToken)){
        # ARMAZENAR NA SESSAO OU BD
        $_SESSION['user_token'] = $getToken;
        header("Location: index.php");
    } else{
       echo "Erro ao gerar autenticacao";
    }
    #fim arquivo end_auth.php
    ?>
    
  • Index.php file with basic examples

    <?php
    require 'config.php';
    # se voce colocar na url ?logout=true
    # vai limpara a sessao e pedir autenticacao novamemente
    # lembrando que voce pode armazenar essa info no BD, XML etc...
    if( isset($_GET['logout']) ){
       unset($_SESSION['user_token']);
    }
    # verifica se tem token
    if( ! isset($_SESSION['user_token']) && empty($_SESSION['user_token'])) {
       # se nao tem token pede permissao para o usuario
       $url = $auth->start();
       header("Location: " . $url);
    }
    # o token ja foi armazenado na sessao conforme arquivo 'end_auth.php'
    $user = new Dropbox\Client($_SESSION['user_token'],APP_NAME,'UTF-8');
    $usuario = $user->getAccountInfo();
    pre($usuario);
    echo "<br/><br/>";
    
    /* EXEMPLO UPLOAD
     * Para fazer upload para o dropbox voce ja deve
     * ter o arquivo localmente ou fazer o upload e depois
     * enviar par ao drop
     *
    */
    $arquivo = fopen("cascata.png",'rb');
    $tamanho = filesize("cascata.png");
    # onde o nome cascata_no_drop.png deve ser o nome que
    # vai ser usado no dropbox lembre de colocar / antes do nome
    $user->uploadFile("/cascata_no_drop.png",Dropbox\WriteMode::add(),$arquivo,$tamanho);
    
    /*
     * EXEMPLO DOWNLOAD
     * informar o path do arquivo no drop
     * informar novo nome para o arquivo "fopen mode 'wb'"
     */
    
     $user->getFile("/cascata_no_drop.png", fopen("cascata_vinda_drop.png","wb"));
    
    /*
     * LISTA O QUE TEM NO DROPBOX
     */
    $lista = $user->getMetadataWithChildren('/');
    pre($lista);
    ?>
    
24.04.2015 / 15:37