I need to read a file from dropbox using PHP. I am running curl_exec. My
PHP curl code works when running on a PHP hosting site ( a2 hosting ). But
the remote web service ( dropbox ) responds with "error 4xx" when I run the
code from PHP on the IBM i.

How to track down the cause?

I am using the Dropbox web service APIs to retrieve the list of items in a
folder. Then the code reads the contents of a file in the dropbox folder.

Here is the PHP code. It is using curl to access the
content.dropbox.com/2/files/download web service. This identical code runs
ok on the a2 hosting PHP hosting site. But when I run it on two different
IBM i PHP servers I get back a "not found" message from dropbox.

another thing. I am able to use the dropbox list_folder web service to get
the list of items in a dropbox folder. That works from IBM i PHP using
curl. Only the files/download api fails. And it only fails on IBM i. )

<!-- getTextFile.php -->

<!DOCTYPE HTML>
<html>
<head>
</head>
<body>

<h2>get text file from dropbox. v1.5</h2>

<?php
$textFile = '/test_upload.txt' ;

echo 'textFile:' . $textFile . '<br>' ;
$rv = getTextFile( ) ;
echo $rv . '<br>' ;

// -------------------------------- getTextFile
------------------------------
function getTextFile( )
{
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "
https://content.dropboxapi.com/2/files/download";);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0 ) ;

$headers = array();
$headers[] = "Authorization: Bearer xxxxxxxxxxxxxxxxx";
$headers[] = "Dropbox-Api-Arg: {\"path\": \"/test_upload.txt\"}";
$headers[] = 'Content-Type: text/plain; charset=utf-8' ;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
return $result ;
}

?>
</body>
</html>

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.