Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieving file from Dropbox using PHP returns 403 Invalid Signature
    primarykey
    data
    text
    <p>I'm trying to download all files from a specific directory in my Dropbox to a directory on my web server, if a file of the same name doesn't already.</p> <p>I'm using this <a href="http://www.sitepoint.com/access-dropbox-using-php/" rel="nofollow noreferrer">SitePoint Tutorial</a> as the guide.</p> <p>The problem I'm having is that the Dropbox API returns an <code>Invalid Signature</code> error when it gets to certain files. I can't see anything odd or special about these files. Some are PDFs, some are PNGs.</p> <p>I've read this <a href="https://stackoverflow.com/a/17070042/426935">could relate to OAuth</a>, but I can't figure it out.</p> <p>I believe errors at the <code>getFile()</code> within the <code>foreach()</code>, depending on the file:</p> <pre><code>&lt;?php require_once "bootstrap.php"; if (!isset($access_token)) { header("Location: authorize.php"); exit; } try { $session = new DropboxSession($config["dropbox"]["app_key"], $config["dropbox"]["app_secret"], $config["dropbox"]["access_type"], $access_token); $client = new DropboxClient($session); $path = "/Stuff/folder_to_download"; $home = $client-&gt;metadata($path); foreach($home['contents'] as $item) { echo "&lt;pre&gt;" . print_r($item, true) . "&lt;/pre&gt;"; $path = $item['path']; if ( $item['is_dir'] == '1' ) continue; // where to save it $dest = $config["app"]["datadir"] . "/" . basename($path); if ( file_exists($dest) ) { echo "&lt;p&gt;File &lt;code&gt;". $dest . "&lt;/code&gt; already exists. Skipped.&lt;/p&gt;"; continue; } // Download file if ($file = $client-&gt;getFile($path, $dest)) { if (!empty($dest)) { unset($file["data"]); echo "&lt;p&gt;File saved to: &lt;code&gt;" . $dest . "&lt;/code&gt;&lt;/p&gt;"; } } } } catch (Exception $e) { echo "&lt;strong&gt;ERROR (" . $e-&gt;getCode() . ")&lt;/strong&gt;: " . $e-&gt;getMessage(); } ?&gt; </code></pre> <p>The <code>authorize.php</code> file <a href="https://github.com/phpmasterdotcom/AccessDropboxUsingPHP/blob/master/authorize.php" rel="nofollow noreferrer">looks like this</a>. <code>bootstrap.php</code> <a href="https://github.com/phpmasterdotcom/AccessDropboxUsingPHP/blob/master/bootstrap.php" rel="nofollow noreferrer">looks like this</a>.</p> <p><strong>Update 1:</strong> I've still not been able to resolve this error. Is there a different set of Dropbox/ PHP code I could use instead of this sitepoint one?</p> <p>Here's the raw error when I remove the try/catch:</p> <pre><code>Fatal error: Uncaught exception 'Exception' with message 'Invalid signature.' in /myapp/lib/dropbox/rest.php:162 Stack trace: #0 /myapp/lib/dropbox/rest.php(85): DropboxRESTClient-&gt;request('https://api-con...', 'GET', NULL, NULL, NULL, true) #1 /myapp/lib/dropbox/session.php(278): DropboxRESTClient-&gt;get('https://api-con...', NULL, true) #2 /myapp/lib/dropbox/client.php(106): DropboxSession-&gt;fetch('GET', 'https://api-con...', '/files/dropbox/...', Array, true) #3 /myapp/download.php(54): DropboxClient-&gt;getFile('/Stuff/Droppod/...', '/myapp/...') #4 {main} thrown in /myapp/lib/dropbox/rest.php on line 162 </code></pre> <p>The <a href="https://github.com/phpmasterdotcom/AccessDropboxUsingPHP/blob/master/lib/dropbox/rest.php" rel="nofollow noreferrer">lib/dropbox/rest.php file is on GitHub</a> for reference.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload