Skip to content

Instantly share code, notes, and snippets.

@alexstone
Created December 19, 2013 23:24
Show Gist options
  • Save alexstone/8047973 to your computer and use it in GitHub Desktop.
Save alexstone/8047973 to your computer and use it in GitHub Desktop.
Routes I used to connect my app to Dropbox. Not shown is the Dropbox config file I made. it contains an array of the app key and app secret.
<?php
/*
|--------------------------------------------------------------------------
| 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);
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment