Created
December 19, 2013 23:24
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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