I'm using dropbox API for PHP, and developed a small app to upload and download files from the dropbox.
This is working fine on my local machine (using WAMP), but not working if I upload it on a server.
Here is an error:
Fatal error: Uncaught exception 'Dropbox\Exception_NetworkIO' with message 'Error executing HTTP request: ' in /dropbox-sdk/lib/Dropbox/Curl.php:73
Here are my cURL settings on the server:
cURL support: enabled
cURL Information: 7.46.0
Age: 3
Features
AsynchDNS: No
Debug: No
GSS-Negotiate: No
IDN: Yes
IPv6: Yes
Largefile: Yes
NTLM: Yes
SPNEGO: No
SSL: Yes
SSPI: No
krb4: No
libz: Yes
CharConv: No
Protocols: dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Host: x86_64-pc-linux-gnu
SSL Version: OpenSSL/1.0.2e
ZLib Version: 1.2.3.4
libSSH Version: libssh2/1.2.6
How can I resolve this?
Edit: Following is my code:
<?php
// Include the Dropbox SDK libraries
require_once "dropbox-sdk/lib/Dropbox/autoload.php";
use \Dropbox as dbx;
// Get access token from dropbox
$appInfo = dbx\AppInfo::loadFromJsonFile("dropbox-sdk/config.json");
$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");
$authorizeUrl = $webAuth->start();
echo "1. Go to: " . $authorizeUrl . PHP_EOL;
echo "2. Click \"Allow\" (you might have to log in first)." . PHP_EOL;
echo "3. Copy the authorization code." . PHP_EOL;
$authCode = \trim(eadline("Enter the authorization code here: "));
list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
print "Access Token: " . $accessToken . PHP_EOL;
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
// Get account info of the user
$accountInfo = $dbxClient->getAccountInfo();
print_r($accountInfo);
?>
Edit: Here is the Stack Trace:
Fatal error: Uncaught exception 'Dropbox\Exception_NetworkIO' with message 'Error executing HTTP request: ' in /dropbox-sdk/lib/Dropbox/Curl.php:73
Stack trace:
#0 /dropbox-sdk/lib/Dropbox/RequestUtil.php(200): Dropbox\Curl->exec()
#1 /dropbox-sdk/lib/Dropbox/WebAuthBase.php(41): Dropbox\RequestUtil::doPostWithSpecificAuth('PHP-Example/1.0', 'Basic d25qZDV0c...', NULL, 'api.dropbox.com', '1/oauth2/token', Array)
#2 /dropbox-sdk/lib/Dropbox/WebAuthNoRedirect.php(80): Dropbox\WebAuthBase->_finish('nNHnBxvAE8qAAAA...', NULL)
#3 /getAccessTokenForDropbox.php(21): Dropbox\WebAuthNoRedirect->finish('nNHnBxvAE8qAAAA...')
#4 {main} thrown in /dropbox-sdk/lib/Dropbox/Curl.php on line 73
The issue was with the curl request being sent by the dropbox API. As dropbox sends curl requests to the IP decided at runtime (for eg. 108.160.173.164), the requests were getting blocked by my server.
White-listing all the connections to 108.160.xxx.xxx helped to resolve this error.