Skip to content

Instantly share code, notes, and snippets.

@alexstone
Created December 19, 2013 23:24
Show Gist options
  • Select an option

  • Save alexstone/8047973 to your computer and use it in GitHub Desktop.

Select an option

Save alexstone/8047973 to your computer and use it in GitHub Desktop.

Revisions

  1. alexstone revised this gist Dec 19, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Dropbox_Connect_Route.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    <?php

    /*
    |--------------------------------------------------------------------------
    | Connect to Dropbox
  2. alexstone created this gist Dec 19, 2013.
    37 changes: 37 additions & 0 deletions Dropbox_Connect_Route.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    /*
    |--------------------------------------------------------------------------
    | Connect to Dropbox
    |--------------------------------------------------------------------------
    */
    Route::get('connect/dropbox', array('before' => 'auth', function() {
    $app_info = Dropbox\AppInfo::loadFromJson(Config::get('dropbox.credentials'));
    $webAuth = new Dropbox\WebAuthNoRedirect($app_info, "PHP-Example/1.0");
    $authorizeUrl = $webAuth->start();

    echo link_to($authorizeUrl, 'Authorize with Dropbox');
    }));
    Route::get('connect/dropbox/finish', array('before' => 'auth', function() {
    $code = Input::get('code');
    $app_info = Dropbox\AppInfo::loadFromJson(Config::get('dropbox.credentials'));
    $webAuth = new Dropbox\WebAuthNoRedirect($app_info, "PHP-Example/1.0");
    list($accessToken, $dropboxUserId) = $webAuth->finish(Input::get('code'));

    // Save or update the Dropbox access record
    $user_dropbox = UserDropbox::where('user_id', Auth::user()->id)->first();
    if(!$user_dropbox) {
    UserDropbox::create(array(
    'user_id' => Auth::user()->id,
    'dropbox_uid' => $dropboxUserId,
    'access_token' => $accessToken
    ));
    }
    else {
    $user_dropbox->dropbox_uid = $dropboxUserId;
    $user_dropbox->access_token = $accessToken;
    $user_dropbox->save();
    }

    $dbxClient = new Dropbox\Client($accessToken, "PHP-Example/1.0");
    $accountInfo = $dbxClient->getAccountInfo();
    print_r($accountInfo);
    }));