public function index() { $session = $this->request->session(); if ($this->request->is('post')) { /* TODO: * Доделать авторизацию dropbox; */ $app = $this->request->data('Appname'); $key = $this->request->data('Key'); $secret = $this->request->data('Secret'); if ($app !== null && $key !== null && $secret !== null) { $dbx_cfg = ['app' => $app, 'key' => $key, 'sec' => $secret]; $session->write('CakeD.dropbox.auth_data', $dbx_cfg); } else { $dbx_cfg = $session->consume('CakeD.dropbox.auth_data'); } $appInfo = new dbx\AppInfo($dbx_cfg['key'], $dbx_cfg['sec']); $webAuth = new dbx\WebAuthNoRedirect($appInfo, $dbx_cfg['app']); $authorizeUrl = $webAuth->start(); $this->set('auth_url', $authorizeUrl); if ($this->request->data('AuthCode')) { list($accessToken, $dropboxUserId) = $webAuth->finish($this->request->data('AuthCode')); $this->set('token', $accessToken); } } }
use Dropbox as dbx; // require_once "dropbox-sdk/Dropbox/autoload.php"; // ---------------------- Send SMS -------------------- echo "\n"; echo "------------Download Call Recordings to dropbox ----------------"; echo "\n"; try { // Dropbox Authentication $appInfo = dbx\AppInfo::loadFromJsonFile("app/config.json"); $webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0"); $authorizeUrl = $webAuth->start(); echo "1. Go to: " . $authorizeUrl . "\n"; echo "2. Click \"Allow\" (you might have to log in first).\n"; echo "3. Copy the authorization code.\n"; $authCode = \trim(\readline("Enter the authorization code here: ")); list($accessToken, $dropboxUserId) = $webAuth->finish($authCode); print "Access Token: " . $accessToken . "\n"; $dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0"); // RC call logs $callRecordings = $platform->get('/account/~/extension/~/call-log', array('type' => 'Voice', 'withRecording' => 'True'))->json()->records; $timePerRecording = 6; foreach ($callRecordings as $i => $callRecording) { if (property_exists($callRecording, 'recording')) { $id = $callRecording->recording->id; print "Downloading Call Log Record {$id}" . PHP_EOL; $uri = $callRecording->recording->contentUri; print "Retrieving {$uri}" . PHP_EOL; $apiResponse = $platform->get($callRecording->recording->contentUri); $ext = $apiResponse->response()->getHeader('Content-Type')[0] == 'audio/mpeg' ? 'mp3' : 'wav'; $start = microtime(true); // Store the file locally
} } if ($accessTokenExcel !== NULL) { try { $dbxClientExcel = new dbx\Client($accessTokenExcel, "PHP-Example/1.0"); $accountInfoExcel = $dbxClientExcel->getAccountInfo(); } catch (Exception $e) { $errors[] = "Could not access Dropbox account excel. Maybe user has revoked access?"; } } if (isBtnRqstDropboxConnectionPrsd()) { $authCode = $_POST['dropbox-key-token-db']; if (empty($authCode)) { throw new Exception("Key token is required."); } list($accessTokenDatabase, $userId) = $webAuth->finish($authCode); DropboxCon::insertAccessToken($accessTokenDatabase, $user->getId(), DropboxCon::SERVICE_APP_DATABASE_BACKUP); header('Location: ' . BASE_URL . "cloud/success"); exit; } else { if (isBtnRqstDropboxConnectExcelKeyPrsd()) { $authCode = $_POST['dropbox-key-token-excel']; if (empty($authCode)) { throw new Exception("Key token is required."); } list($accessTokenExcel, $userId) = $webAuth->finish($authCode); DropboxCon::insertAccessToken($accessTokenExcel, $user->getId(), DropboxCon::SERVICE_APP_EXCEL_BACKUP); header('Location: ' . BASE_URL . "cloud/success"); exit; } else { if (isBtnRqstTokenDatabaseDropboxKeyPrsd() || isBtnRqstTokenExcelDropboxKeyPrsd()) {
$argAuthFileOutput = $argv[2]; try { list($appInfoJson, $appInfo) = dbx\AppInfo::loadFromJsonFileWithRaw($argAppInfoFile); } catch (dbx\AppInfoLoadException $ex) { fwrite(STDERR, "Error loading <app-info-file>: " . $ex->getMessage() . "\n"); die; } // This is a command-line tool (as opposed to a web app), so we can't supply a redirect URI. $webAuth = new dbx\WebAuthNoRedirect($appInfo, "examples-authorize", "en"); $authorizeUrl = $webAuth->start(); echo "1. Go to: {$authorizeUrl}\n"; echo "2. Click \"Allow\" (you might have to log in first).\n"; echo "3. Copy the authorization code.\n"; echo "Enter the authorization code here: "; $authCode = \trim(\fgets(STDIN)); list($accessToken, $userId) = $webAuth->finish($authCode); echo "Authorization complete.\n"; echo "- User ID: {$userId}\n"; echo "- Access Token: {$accessToken}\n"; $authArr = array("access_token" => $accessToken); if (array_key_exists('auth_host', $appInfoJson)) { $authArr['auth_host'] = $appInfoJson['auth_host']; } if (array_key_exists('host_suffix', $appInfoJson)) { $authArr['host_suffix'] = $appInfoJson['host_suffix']; } $json_options = 0; if (defined('JSON_PRETTY_PRINT')) { $json_options |= JSON_PRETTY_PRINT; // Supported in PHP 5.4+ }
<html> <head> <meta charset="UTF-8"> <title>Cloud Storage Pool (CSP) - Dropbox Autorisierung</title> </head> <body> <h1>Cloud Storage Pool (CSP) - Dropbox Autorisierung</h1> <?php require_once "config.inc.php"; require_once "api/Dropbox/autoload.php"; use Dropbox as dbx; $appInfo = dbx\AppInfo::loadFromJson($config_dropbox_appinfo); $webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0"); if (isset($_POST['auth_code'])) { list($accessToken, $dropboxUserId) = $webAuth->finish($_POST['auth_code']); echo "Autorisierung der App ist erfolgt. <br>"; echo "Bitte tragen Sie den unten stehenden Access Token in die CSP Konfigruration ein. <br>"; echo "Access Token: " . $accessToken . "\n"; } else { $authorizeUrl = $webAuth->start(); if ($authorizeUrl) { echo "1. Klick auf <a href='" . $authorizeUrl . "' target='_blank'>Link</a>, Autorisierung der App und Kopieren des Codes<br />"; echo "2. Den Code hier einfügen und absenden:<br /><br />"; echo "<form method='post'>"; echo "\t<input type='text' name='auth_code''>"; echo "\t<input type='submit' value='Code absenden' class='button' />"; echo "</form>"; echo "3. Den anschließend angezeigten Access Token in die CSP Konfigruration einfügen.<br /><br />"; } else { echo "Keine gültige AuthURL erhelten. Bitte Key und Secret prüfen."; }