dropbox.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. require_once 'Dropbox/autoload.php';
  3. OCP\JSON::checkAppEnabled('files_external');
  4. OCP\JSON::checkLoggedIn();
  5. if (isset($_POST['app_key']) && isset($_POST['app_secret'])) {
  6. $oauth = new Dropbox_OAuth_Curl($_POST['app_key'], $_POST['app_secret']);
  7. if (isset($_POST['step'])) {
  8. switch ($_POST['step']) {
  9. case 1:
  10. try {
  11. if (isset($_POST['callback'])) {
  12. $callback = $_POST['callback'];
  13. } else {
  14. $callback = null;
  15. }
  16. $token = $oauth->getRequestToken();
  17. OCP\JSON::success(array('data' => array('url' => $oauth->getAuthorizeUrl($callback), 'request_token' => $token['token'], 'request_token_secret' => $token['token_secret'])));
  18. } catch (Exception $exception) {
  19. OCP\JSON::error(array('data' => array('message' => 'Fetching request tokens failed. Verify that your Dropbox app key and secret are correct.')));
  20. }
  21. break;
  22. case 2:
  23. if (isset($_POST['request_token']) && isset($_POST['request_token_secret'])) {
  24. try {
  25. $oauth->setToken($_POST['request_token'], $_POST['request_token_secret']);
  26. $token = $oauth->getAccessToken();
  27. OCP\JSON::success(array('access_token' => $token['token'], 'access_token_secret' => $token['token_secret']));
  28. } catch (Exception $exception) {
  29. OCP\JSON::error(array('data' => array('message' => 'Fetching access tokens failed. Verify that your Dropbox app key and secret are correct.')));
  30. }
  31. }
  32. break;
  33. }
  34. }
  35. } else {
  36. OCP\JSON::error(array('data' => array('message' => 'Please provide a valid Dropbox app key and secret.')));
  37. }
  38. ?>