2

Hello guys I'm new to composer thing. Previously I had configured dropbox manually in my codeigniter project but my head asked me to do it using composer now. I have configured composer somehow and installed dropbox using composer. Now this was my login function which I used before

      public function login() {
//          $this->CI->session->set_userdata('state', 1);
          $this->CI->session->dropbox_success = false;
          $oauth = new Dropbox_OAuth_PHP($this->CI->config->item('APP_KEY'), $this->CI->config->item('APP_SECRET'));
          $this->dropbox = new Dropbox_API($oauth);

          if ($this->CI->session->state) {

              $state = $this->CI->session->state;
          } else {
              $this->CI->session->set_userdata('state', 1);
              $state = 1;
          }
          switch ($state) {

              /* In this phase we grab the initial request tokens
                and redirect the user to the 'authorize' page hosted
                on dropbox */
              case 1 :
//                  echo "Step 1: Acquire request tokens\n";
                  $tokens = $oauth->getRequestToken();

//                  echo "<a href='".$oauth->getAuthorizeUrl(site_url())."' >Authorize</a>";
//                  header('Location: '. $oauth->getAuthorizeUrl());
                  echo "<a href=" . $oauth->getAuthorizeUrl(site_url("somePAth")) . "><img width='30px' src='" . base_url() . "somePAth'> Connect Dropbox</a>";
                  $this->CI->session->set_userdata('state', 2);
                  $this->CI->session->set_userdata('oauth_tokens', $tokens);
                  return FALSE;

              /* In this phase, the user just came back from authorizing
                and we're going to fetch the real access tokens */
              case 2 :

                  if (!$this->CI->session->oauth_tokens) {
                      $this->CI->session->set_userdata('state', 1);
                      header("Location: ?");
                  }
                  $oauth->setToken($this->CI->session->oauth_tokens);
                  $tokens = null;
                  try {
                      $tokens = $oauth->getAccessToken();
                  } catch (Exception $e) {
                      $this->CI->session->set_userdata('state', 1);
                      header("Location: ?");
                      return false;
                  }

                  $this->CI->session->set_userdata('state', 3);
                  $this->CI->session->set_userdata('oauth_tokens', $tokens);
                  header("Location: ?");
              case 3 :
//                  echo "The user is authenticated\n";

                  $this->CI->session->dropbox_success = true;
                  $oauth->setToken($this->CI->session->oauth_tokens);
                  echo "<a class='btn btn-primary float-right' href=" . base_url('somePath') . ">Disconnect Dropbox</a>";
                  return true;
          }
      }

Now after I installed dropbox using composer and after going through the configration I created the app-info.json file and included the code which dropbox asked me to add in the code which is $oauth = dbx\AppInfo::loadFromJsonFile("../config/app-info.json"); in place of the second uncommented line but it's not working. It is throwing me this error.

ERROR : Exception of type 'Error' occurred with Message: Class 'dbx\AppInfo' not found in File D:\Ampps\www\softcake\application\libraries\Dropbox.php at Line 30

So can somebody please guide me what is it that I'm doing wrong and redirect me to some solution which would help me in configuring drop box in my app. Thanks in advance

Garden
  • 243
  • 1
  • 4
  • 11
  • Put `use \Dropbox as dbx;` at the start of the file. Before class code. [Docs(https://www.dropbox.com/developers-v1/core/start/php). – Tpojka Aug 09 '16 at 06:01
  • @Tpojka I have placed it but now it's saying that app-info.json path does not exists. I haved placed that file in the same directory in the same location from where I calling the above code but it's not working – Garden Aug 09 '16 at 06:29
  • Try with moving that file next to `index.php` (for testing purposes). – Tpojka Aug 09 '16 at 07:05
  • @Tpojka which index are you talking about. Are you taling about the index of the project or some other. My code structure is according to code igniter at the monent – Garden Aug 09 '16 at 07:29
  • and one more thing that file is right next the file from where I'm trying to open it – Garden Aug 09 '16 at 08:28
  • @Tpojka it started working don't know how but it did. I just restarted apache but now it's throwing me a new error – Garden Aug 09 '16 at 08:43

0 Answers0