Access Dropbox Using PHP

In this article we’ll explore the Dropbox PHP API by building a simple client for accessing files in a Dropbox account. The client will perform some basic operations, such as authentication, listing files, and uploading and downloading files.

To keep the article short and readable, I’ll keep the included code to a minimum and instead refer you to the full code available on GitHub. To run the code, you’ll need PHP with cURL support and obviously a Dropbox account.

Your starting point for anything related to development with Dropbox should be the Dropbox Developers Center where you can find the API reference along with its basic concepts and best practices. You can also download the official SDKs, but PHP isn’t listed among the supported languages. There’s a link to a third party PHP SDK on Github.

Our client will be structured more like the official Python client, but I took some ideas and code from the PHP SDK above, especially for the OAuth part. We’ll have a DropboxSession object and a DropboxClient object. The first will take care of the hard part: obtaining and managing access credentials from Dropbox. The client object will then use the session object to perform the API calls and get the data. Underneath the session object there is a DropboxRESTClient object to perform the HTTP calls using cURL.

Tell Dropbox About your App

First of all we need to register our application with Dropbox in order to obtain a unique API key pair. We’ll need these keys to “introduce” our application and ask for authorization.

Log into the Developers Center and follow the “MyApps” link, then select “Create an App”. Dropbox will ask you for a name, description, and access type for your application.

The access type parameter specifies where your application will be able to read and write files. The recommended value is “App folder”, a sandbox directory that will be created inside the user’s home. By selecting “Full Dropbox” the application will see the user’s entire Dropbox.

Once your application is created, there will be an options page where you can edit its details and find its access credentials.

Newly created application are in “Development status”. This allows us to start developing immediately and enables up to five other users to test it. When the app is ready for release, we can apply for productions status and the Dropbox team will review it to make sure that it conforms to their terms and conditions and branding guidelines.

Coding the Application

I placed my code in a subdirectory of my local Apache set-up so that it’s reachable at the URL http://localhost/mydropbox. The directory structure is:

The bootstrap.php file performs the application’s start-up and will be included in each of the front-end files, so let’s start by discussing that.

I initialize a global $config variable as an empty array and then specify some configuration values. The first three are Dropbox-related: the access key, secret key, and access type from your app’s details page. I then define some other useful settings: the base root path of the application, the path to save some data, and the path of a PHP file that will contain the access token for the application.

This access token file file doesn’t exist in the beginning; it’s created by the authorize.php page and is filled with the credentials provided by Dropbox. It will be a standard PHP file, and if exists will be included later by this script. The contents of the token file will be similar to:

<?php
$access_token = array (
  "oauth_token_secret" => "abcdefghilmnopqr",
  "oauth_token" => "stuvwxyzabcdefgh",
  "uid" => "1234567"
);

oauth_token and oauth_token_secret are the access credentials, and uid is the unique ID of the user.

In the next section of the bootstrap file I set PHP error behavior and perform some requirements check; in order to run the application the data directory must exists and be writable and the auth.php file must be writable if it exists. This ensures the application can do its job freely.

Finally, I include our libraries, initialize the PHP session, set an empty $access_token (which will be filled later), and, if it exists, include the auth.php file.

Each frontend script will run inside a main try/catch block. Before digging into the library code we first need to understand the flow, so I’ll start with the authorization cycle.

Authorization

The first time our application is run, the following condition in the index.php file will be true:

<?php
if (!isset($access_token)) {
    header("Location: authorize.php");
    exit;
}

The access token is empty so I’m redirecting the user to the authorize.php page that will manage the authorization process.

After the bootstrap phase, I make another check for an existing token. This ensures that this script is run only if we don’t have a token. In order to avoid an infinite redirect loop, the auth.php file is deleted by the main catch block of a script if the error code returned is 401 (invalid token).

The first thing I do in every script is create a new DropboxSession object with our API keys. When we call the script directly, the first condition will be false and the else block is executed. The session object connects to Dropbox and asks for a temporary token. The token is then parsed into an array and stored into the $_SESSION variable for the next phase.

We build the authorization URL using this token. The user should be redirected or prompted to visit the URL where he will decides whether to allow or deny access to his data.

The authorization URL can contain the return URL as an optional parameter. I just pass the current script’s URL, so if the user authorizes the application he’s redirected back to our script, this time with the oauth_token and uid values passed by query string. The first condition now evaluates true, so we can go on and request a permanent access token.

The $token array for this request is built with this new oauth_token and the previous oauth_token_secret, this is then passed to the obtainAccessToken() method. In case of success we have our permanent (until revoked) access token. This must be stored somewhere; the obvious choice is a database, but for this example we’ll export it as valid PHP code using the native var_export() function and write it to our auth.php file. Then the user is redirected to the index page which is the simplest script.

At the beginning of our try/catch block a new DropboxSession object is created, this time with the permanent $access_token as fourth argument. This object is used to create the DropboxClient object. These two steps are common for all the other scripts.

The public methods of the client are mapped to the corresponding Dropbox API calls. I’m calling the accountInfo() method that returns an array containing the user’s details: unique id, name, email, quota info and referral link (refer to the official documentation for more details).

Behind the Scenes: the REST and Session Objects

Now that we have an overview of the surface flow, let’s see what happens under the hood, our Dropbox library is contained in the lib/dropbox directory and consists of three classes.

The REST Object

The lowest level class of our library is the REST client (see lib/dropbox/rest.php). This class is a simple wrapper for cURL. It performs the HTTP calls and return the output in raw or encoded format, or throws an exception in case of an error.

The constructor checks if cURL is installed on the system, or throws an exception. Then it tries to initialize the internal $curl handler with the $curlDefaults setting. The handler is unset inside the destructor.

The error(), errno(), and close() methods are self-explanatory. Then, we have a series of utility methods, get(), post(), and put(), all simple wrappers for the main request() method that does the real work.

First we set the URL to fetch, then the HTTP method and the required parameters, additional headers and POST fields (if any). The parameters for the GET and PUT methods are passed along the URL by the caller method.

Before making the call, we need to tell cURL to retrieve the full content including HTTP headers (set option CURLOPT_HEADER) because some API methods (ex file_get()) put their information in the headers.

The cURL request is executed with curl_exec() storing the result into $response and the $info variable is filled by curl_info() with the details about the last execution. If the method is PUT we’ll also have to close the input file handle.

With the $response content and the $info values we parse the result and separate the HTTP headers from the body. By default, the body is returned as JSON-decoded unless the $raw argument is set true.

Before going on, there’s an error check. The Dropbox API uses HTTP error codes for error notifications. If the status code is greater than 400 then something went wrong and an error message is stored in the body content. I extract this message and throw an exception. If there are no errors the HTTP headers are parsed and the result is returned as array containing the status code, the headers, and the body.

The Session Object

The DropboxSession object extends the basic REST client to fill our needs:

  • perform the initial authentication/authorization flow,
  • include the obtained authentication data in each subsequent REST request.

The constructor simply initiazlizes the internal variables. Another simple method is buildAuthorizeURL() which builds the authorization URL from the temporary token. The most important methods of the class are:

  • obtainRequestToken() – request a temporary OAuth access token.
  • obtainAccessToken() – request the permanent OAuth access token for the application.
  • fetch() – perform a REST call including all the necessary authentication and signature parameters.

These three methods have a similar flow. First they build the basic destination URL and fill the $params associative array with the required oauth_* keys/values to send. Every API call must provide a timestamp and a unique random-generated hash, the $nonce parameter.

Then the signature is generated using the HTTP method name, the URL, and the parameters. It’s then queued to the $params array using the oauth_signature key. The URL is fetched with the given HTTP method and the body part of the response is returned. For the GET and PUT methods, the query string is generated and appended to the URL using the native http_build_query() function.

The obtainRequestToken() and obtainAccessToken() are nearly identical: the first doesn’t use a token and is called with a GET HTTP method. The second is called with a POST HTTP method and must include the token obtained with the previous call. This token is then used as part of the signature key for all the following API calls.

The fetch() method performs some additional tasks. First it takes an array called $args with any additional arguments required by the specific API, for example the path of the resource to list or the file to upload/download. These parameters are merged with the $params array before the signature is generated. The only exception is the input file argument, used by the PUT method to upload a file, which is extracted and kept for later. A switch statement is used to tell the right HTTP method to call.

The DropboxSession class has also two utility methods, encodeParams() and getSignature(), called by the main methods above. encodeParams() prepares the request’s parameters to be signed, while getSignature() generates an OAuth request signature for the given API call.

The Final DropboxClient Object

The DropboxClient object is our high-level interface with Dropbox. It exposes the public API methods, uses the mid-level DropboxSession object to perform the API calls, and returns a processed output to the calling script. For this article I’ve implemented a limited suite of methods:

  • accountInfo() – fetch the current Dropbox user’s details.
  • metadata() – fetch information about a Dropbox object (file or folder) and retrieve a list of the content for folder objects.
  • getFile() – download a file and its metadata and optionally saves it to disk.
  • putFile() – upload a local file to a remote Dropbox path.

The session object and the base API URLs are stored as internal variables and initialized by the constructor.

All the methods follow more or less the same approach, so I’ll point out the differences. All methods that deal with a path must prepend the Dropbox root path to each call. The root path depends on the access type of the application, and can be “dropbox” if the application has full access or “sandbox” if the application has limited access. If this value doesn’t match the application’s remote settings, an error is returned.

The common steps performed by each method are:

  1. Check and prepare the argument list.
  2. Perform the HTTP call.
  3. Parse and return the response.

The accountInfo() method is the simplest; it calls its URL with no arguments and returns the associative array with the response.

The metadata() method is used by list.php file to fetch and display the contents of the directory. The only required parameter is the path of the file or directory to check, but it allows us to specify all of the other parameters of the corresponding API call. If the $path argument is a file, the returned array contains its metadata. If it’s a folder, the content key contains the list of its files unless the $list argument is false. We can limit the size of the content with the $fileLimit argument (up to a maximum of 25,000) and we can ask for a specific revision of the file or folder (see the API reference for details).

It’s important to note that the Dropbox API returns a hash value for each call. If we want to list the contents of a folder and provide a $hash parameter to our method, the API checks whether the output has changed since the last call. If not, it returns a status code of 301 (not modified). The Dropbox team recommends caching the results and relying on these values for folder listings to optimize performance.

The getFile() method is used to retrieve a file stored in the user’s Dropbox. The entire file content is returned by the call in case of success, and its metadata is stored in the custom HTTP header x-dropbox-metadata as a JSON string. The return value of this method is an associative array that contains the name, mime type, metadata and content. In addition I’ve added an $outFile parameter to save the file directly on disk.

The download.php file shows a demo of this method in action. In this example, the downloaded file is saved directly to the application’s data directory and the content part of the response is emptied.

The putFile() method uploads a file from our local storage to the user’s Dropbox using the PUT HTTP method, which is preferred by the Dropbox team instead of POST. This method checks that the local file exists and doesn’t exceed the 150MB API limit before any other common action.

The supported parameters for this method, in addition to the source file path, are the destination folder, an optional alternative name and an overwrite option. If this last option is false and the remote file exists, the uploaded file is renamed with a progressive number (for example, test.txt becomes test (1).txt). The API also allows for an optional parent_rev parameter to manage revisions, but in order to keep things simple I decided to omit it.

Summary

This is just a small part of the Dropbox API, but it can be enough as a starting point to develop your own applications. For me, it was also a good occasion to play with OAuth. Feel free to refine and expand the code that accompanies this article to suit your needs and, as always: happy coding!

Image via Fotolia

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • http://github.com/BenTheDesigner Ben Tadiar

    I’ve heard of great minds think alike, but this is uncanny! There are whole blocks of code identical to those I pushed to my Dropbox SDK on GitHub months ago. See the (real) full code here github.com/BenTheDesigner/Dropbox :)

    • http://github.com/BenTheDesigner Ben Tadiar

      By the way – I don’t mind, I just don’t get why the author would spend time copying and modifying my code to make it look like his own rather than forking and contributing.

      • Naren

        Very nice. What they should have probably done is to ask you to write the article for them :)

      • http://sergiufalcusan.ro smotru

        Hey Ben, i have tried some hours to use your code and nothing. This tutorial saved me! Also thank you Ben for your contribution!

    • http://www.vtardia.com/ Vito Tardia

      Hi Ben,

      yes, I used your code and I stated clearly at the beginning of the article, along with a link to your official repository. I have no intention to make it look mine.

      I designed this tutorial to use an approach similar to the official Dropbox python client, I pasted entire portions of your code, mainly the OAuth part, and adapted to the rest of the article’s code. The entire package is for learning purpose, it’s not a finished product and anyway I would never sell or distribute someone else’s code ad mine. :)

      • Trung Woodman

        Didn’t had the feeling he stole or make it look like his own.
        He contributed by writing this tutorial. Good job. I gonna use both inputs.

  • Alex

    Hello, Vito! I’m trying to set up your magnificent script, but i have some troubles. Then i’m trying yo open index.php in browser – it redirects me to authorize.php and shows up a warning:
    PHP SCRIPT ERROR!
    Warning: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/us6498/sonya/lib/dropbox/rest.php on line 51
    If you beleive that this error is due to the server configuration problems please contact your local web-hosting support team.

    cURL Error:

    Is there a problem with my hosting?

  • Skrln

    Hi Vito
    I’ve been using your example and liked it a ton. For a project however I would like to request an addition to your class on github.
    Would you be willing to incorporate GetDownloadLink() into your class? This would be immensely helpful!
    Many thanks in advance!

    • http://www.vtardia.com/ Vito Tardia

      Hi Skrin,

      there are two API calls to get the download link: the /media method which returns the direct link to a file bypassing the server and the /share method which creates and return a shared link.

      In order to incorporate them in the library the code is very simple and could be pasted from other methods, for example:
      // Prepend the right access string to the desired path
      if (‘dropbox’ == $this->accessType) {
      $path = ‘dropbox’ . $path;
      } else {
      $path = ‘sandbox’ . $path;
      } // end if

      // Execute
      $response = $this->Session->fetch(‘POST’, $this->dropboxAPIURL, ‘/media/’ . $path, $args);
      return $response['body'];

  • Lupita

    What should I do if I need access to another dropbox user account? Do I need to ask him to register my app, so I can get an app key and app secret?

    • http://www.vtardia.com/ Vito Tardia

      Lupita, you need a first set of credentials (yours) to register your app into Dropbox. Then you have to store a different token for each user who authorizes the app.

  • Josh Haimson

    Hi Vito,

    I’ve set up your script and it works really well, thanks. Do you know how I would go about adding a create new directory function and also a delete file/directory function?

    Thanks,
    Josh

  • Chris

    I simply get a Parse error: syntax error, unexpected ‘}’, expecting T_STRING in /home/dewwee/public_html/dropbod/lib/dropbox/client.php on line 137

    • Chris

      Client php has a / at the end of line 136 that shouldn’t be there. Removing it corrected the problem.

  • Chris

    I should add I have not edited the script; but I am simply trying to get the script to display the contents of the “Public” folder / subfolders / files so they can be clicked on and accessed.

    • http://www.vtardia.com/ Vito Tardia

      Hi Chris, got it, there’s a random “” at the end of that line, will fix it as soon as possible, thank you!

  • http://babakfakhamzadeh.com Babak Fakhamzadeh

    You’ve got a return URL hardcoded in your code and the typo is still in there, but these are minor gripes. The code works like a charm.

  • http://projetosobrinho.wordpress.com Antonio Mano

    Appears only: “Unable to get request token”
    What am I doing wrong??
    And where I get my uid?

    • Kenrick

      Same here, I also get this message. I’m testing this on my local server (http://localhost/mydropbox/) which is using wampserver 2.0; with PHP 5.3.8 (with PHP cURL extension); Apache 2.2.21; and MySQL 5.5.8.

    • http://www.vtardia.com/ Vito Tardia

      Hi Antonio and Kenrick,

      the message “Unable to get request token” is generated by the authorize.php file when starting a new authorization cycle. The exception is triggered when the $session->obtainRequestToken() method returns an empty token.

      You can debug this case by dumping the variables $requestTokenUrl and $query used near line 164 of file lib/dropbox/session.php and the corresponding $response array that should contain the token in the ‘body’ key. In my local installation is still going right, by debugging these two vars we should see what’s happening to you.

      The ‘uid’ parameter is returned by Dropbox when this first step is successful and must be stored somewhere.

      Hope that helps, let me know

      – Vito

      • Nibin

        Hi Vito,
        I tried printing the variables query and requesturltoken and both contains the required value.But when I tried printing the response["body"],it is empty.Please help me..

  • Kenrick

    Hi, thank you for the response. Now I’m having another problem when accessing folder which name contain spaces (e.g. “/Public/Shared Folder”). (i.e. I can access folder which name do not contain any space (e.g. “/Public”)) It always returns “ERROR (403): Invalid or missing signature”. I’ve tried to rawencode the $path (by adding $path=rawencode($path);) in client.php but it didn’t have any effect. Any suggestion to fix this? Thank you very much.

    • http://www.vtardia.com/ Vito Tardia

      We have a little issue here. I have a folder called “Linux Programming”, the path must be encoded leaving the “/” path separator unaltered. urlencode() and rawurlencode() don’t work because the path separator is also encoded. If I manually write “Linux%20Programming” it works.

      • Kenrick

        Oh, thank you. That helps me very much. I use PHP’s str_replace() function to replace the spaces in $path to “%20″ and it works well.

    • Nibin

      How did you fix the previous error? (unable to get request token ?
      Any help is appreciated..

  • suresh

    hi , i read your article and download full code from Github. my problem is, i don’t know where to give App key and App Secret in your API.

  • http://daberet.co.il david

    Hi suresh,
    U need to write it in the bootstrap.php in line 11 && 12 :)

  • Rodolfo

    Hi Vito, thank your for your work and contribution. I am currently using your code to download files from Dropbox to my server’s folders. No problem with it. I am trying to use the function create($path) to create a folder on my Dropbox account. I think everything is fine in my function but I always get “ERROR (403): Invalid or missing signature”. I tried many thing but with no success.
    I had the same using the download.php script but I solved that discovering that it was not possible to download a file with spaces in the filename (maybe Dropbox API does not accept such a kind of calls..).
    Here is my code for the function (placed in lib/dropbox/client.php):
    public function create($path)
    {
    $root = “/”;
    if (“dropbox” == $this->accessType) {
    $root = “dropbox” . $root;
    }
    else {
    $root = “sandbox” . $root;
    }

    $call = “/fileops/create_folder/”;
    $params = array($root, $path);
    $this->Session->fetch(“POST”, $this->dropboxAPIURL, $call, $params);
    }
    Here is my call to the function(placed in index.php)
    Could you have any idea on why I am getting that?
    Many thanks.

    • http://www.vtardia.com/ Vito Tardia

      Hi Rodolfo, thank you for your feedback. In effect I’ve only tried to read folders, I’ll have to do some test starting from your code and let you know.


      Vito

      • Rodolfo

        Many thanks. Unfortunately I was not lucky with all my tests at now..

        • http://www.vtardia.com/ Vito Tardia

          Hi Rodolfo,

          I added this method to my client library and it works:

          public function createFolder($folder) {

          $folder = trim($folder, ‘/’);

          $args = array(
          ‘root’ => $this->accessType,
          ‘path’ => $folder
          );

          $response = $this->Session->fetch(‘POST’, $this->dropboxAPIURL, ‘/fileops/create_folder’, $args);

          return $response['body'];

          } // end function

  • Mayz

    Hi, Vito
    I var_dump($response) and the result is ["body"]=> bool(false)
    What should I do next? I stuck at Unable to get request token.

  • Save in my computer

    Hello,

    I tried this and works perfect for me. Now, I want to save a file from dropbox to my computer directly, How can I change the code to do so? At the moment my code is copying my file to the server and, after that I copy it from my server to my computer. How can I do it in only one step? I’m not an expert in PHP, so any help is appreciated.
    Thanks in advance.
    Mário

    • http://www.vtardia.com/ Vito Tardia

      Hi Mario,

      inside the client’s getFile() method the $response['body'] variable contains the actual data of the remote file. You can write a variant of this method that outputs the file directly to the browser with the correct http content-type headers to trigger a download action.


      Vito

  • Derzz Ale

    It manages to make a clearance with var_dump $ requestTokenUrl and $ query but not may be happening with the project .. please help me …

    • Raj Chouhan

      it gives. Unable to get request token! Why?

  • http://www.vtardia.com/ Vito Tardia

    @Raj, Nibin, Derzz: make sure your app is registered correctly with Dropbox. If the error persists I would use a tool like Poster for Firefox (https://addons.mozilla.org/en-us/firefox/addon/poster/) to see exactly what’s happening.

    • http://sorteiospt.com Júnio Branco

      Hey Vito, first of all thank you for this. really appreciate your work.
      I have done some debugging as I was having the same issues as some people have reported. The error “Unable to Request Token” is due to a configuration with the cURL. I had this issue myself, and to fix this by doing the following :
      Line 32 of rest.php : CURLOPT_USERAGENT => “Dropbox REST PHP Client/1.0″

      I added a new parameter after this line,
      CURLOPT_SSL_VERIFYPEER => false

      So my line 32 and 33 ended up being:
      CURLOPT_USERAGENT => “Dropbox REST PHP Client/1.0″,
      CURLOPT_SSL_VERIFYPEER => false

      Sorry for the long post but I hope this helps!

      • http://www.vtardia.com/ Vito Tardia

        Hi Júnio, thanks to you for the time spent debugging. I went ahead and searched why this can happen. The setting CURLOPT_SSL_VERIFYPEER tells cURL to not check the SSL certificate from the remote host, it could be set to false if the remote server is, for example, a private development server, but for an entity like Dropbox it sounded a bit strange to me.

        I’ve discovered that certain installations of cURL (often on Windows) don’t know where to look for CA certificates. You can use the CURLOPT_CAINFO and CURLOPT_CAPATH settings to specify where to find the certificates. The CURLOPT_CAINFO setting can also be specified as global in your php.ini file: http://www.php.net/manual/en/curl.configuration.php

        Can you try and see if it works for you?


        Vito

      • Sreenivasan

        Hi Júnio Branco,

        Your comment solved my problem. Thanks buddy :)

  • gekkodb

    Hi, im not expert in PHP, actually im just starting in this lenguaje. Im trying to run the api for dropbox and i already created the app in dropbox and configure the app key and app secret in the code but when i run the index, i get this message: Unable to get request token. Can you tell me why?

    • http://www.vtardia.com/ Vito Tardia

      Hi gekkodb,

      it could be the same problem I discussed with Júnio in the previous comment thread. You can either disable the SSH certificate validation in cURL or (recomended) configure the CA directory.

      Hope that helps


      Vito

  • Derzz Ale

    hi, i have this problem:
    Warning: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/u149621304/public_html/mydropbox/mydropbox/lib/dropbox/rest.php on line 51
    ERROR (0): cURL Error:

    Help´me please

    • http://www.vtardia.com/ Vito Tardia

      Hi Derzz,

      you should look at your server or provider configuration and update it. The safe mode is deprecated in latest PHP and the open_basedir can be configured properly, it depends on your provider.

      Hope that helps


      Vito

  • Sharan Munyal

    Hi,
    Thanks for the code. It looks amazing. I ran the project for the first time and I see the following error:
    Notice: Use of undefined constant CURLOPT_AUTOREFERER – assumed ‘CURLOPT_AUTOREFERER’ in /var/www/sharan/DropboxUsingPHP/authorize.php on line 11 Notice: Use of undefined constant CURLOPT_FAILONERROR – assumed ‘CURLOPT_FAILONERROR’ in /var/www/sharan/DropboxUsingPHP/authorize.php on line 11 Notice: Use of undefined constant CURLOPT_FOLLOWLOCATION – assumed ‘CURLOPT_FOLLOWLOCATION’ in /var/www/sharan/DropboxUsingPHP/authorize.php on line 11 Notice: Use of undefined constant CURLOPT_RETURNTRANSFER – assumed ‘CURLOPT_RETURNTRANSFER’ in /var/www/sharan/DropboxUsingPHP/authorize.php on line 11 Notice: Use of undefined constant CURLOPT_FRESH_CONNECT – assumed ‘CURLOPT_FRESH_CONNECT’ in /var/www/sharan/DropboxUsingPHP/authorize.php on line 11 Notice: Use of undefined constant CURLOPT_FORBID_REUSE – assumed ‘CURLOPT_FORBID_REUSE’ in /var/www/sharan/DropboxUsingPHP/authorize.php on line 11 Notice: Use of undefined constant CURLOPT_TIMEOUT – assumed ‘CURLOPT_TIMEOUT’ in /var/www/sharan/DropboxUsingPHP/authorize.php on line 11 Notice: Use of undefined constant CURLOPT_CONNECTTIMEOUT – assumed ‘CURLOPT_CONNECTTIMEOUT’ in /var/www/sharan/DropboxUsingPHP/authorize.php on line 11 Notice: Use of undefined constant CURLOPT_ENCODING – assumed ‘CURLOPT_ENCODING’ in /var/www/sharan/DropboxUsingPHP/authorize.php on line 11 Notice: Use of undefined constant CURLOPT_USERAGENT – assumed ‘CURLOPT_USERAGENT’ in /var/www/sharan/DropboxUsingPHP/authorize.php on line 11 cURL is not installed on this system

    Could you please help me fix this?

    Thanks,
    Sharan

    • http://www.vtardia.com/ Vito Tardia

      Hi Sharan, it seems there is something wrong with your cURL installation. You should check that cURL is installed on your machine and that the PHP cURL extension is installed too.


      Vito

  • share LInk

    Hi Vito,
    Thanks for your tutorial. I tried many codedumps from github, but managed to get it running only with yours.
    Quick question. With ‘Share’ or ‘Media’ link, when I try to get the link, what is the args{} value that I should pass. I would like the result URL in 1 single line.
    cheers
    Lawrence

    • http://www.vtardia.com/ Vito Tardia

      Hi Lawrence,

      both ‘media’ and ‘share’ can be called without args but can have the optional ‘locale’ arg. In addition with ‘share’ you can youse the ‘short_url’ arg set to false to obtain the real file preview url. The result is always a json that you have to decode.

      hope that helps


      Vito

      • Lawrence

        Yes Vito, I tried share_link without the args, and the JSON output is an object with 2-3 lines. Is there a way to decode the JSON and just get only the url link.
        Thanks
        Lawrence

        • http://www.vtardia.com/ Vito Tardia

          Sure, inside the method or function that calls the share action use json_decode() to transform the JSON into a PHP object or associative array, then return the value you need to the calling script.