2013-04-24 27 views
0

我在嘗試使用PHP和Dropbox API上載文件時遇到問題。當cURL執行時,我得到一個頁面未找到錯誤。這表明一個URL的問題,但我不明白這是錯的。PHP Dropbox API - 未找到頁面使用files_put發生錯誤

該文件存在且所有OAuth都在工作。

截圖錯誤: Page not found error

這是在代碼中使用了 - 我失去了一些東西在這裏?

$filePathName = "/path_to_file/my_image.png"; 
$url = "https://api-content.dropbox.com/1/files_put/sandbox/my_folder/my_image.png"; 

$headers = array("Content-Type: ".mime_content_type($filePathName)."\r\nContent-Length: ".filesize($filePathName)."\r\n". 
    "Authorization: OAuth oauth_version=\"1.0\", oauth_signature_method=\"PLAINTEXT\", oauth_consumer_key=\"".DROPBOX_APP_KEY."\", oauth_token=\"".DROPBOX_OAUTH_ACCESS_TOKEN."\", oauth_signature=\"".DROPBOX_APP_SECRET."&".DROPBOX_OAUTH_ACCESS_SECRET."\"" 
); 

$fh = fopen($filePathName, "rb"); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_PUT, 1); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 
curl_setopt($ch, CURLOPT_INFILE, $fh); 
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($filePathName)); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$apiResponse = curl_exec($ch); 

fclose($fh); 

die("Response:<br />".$apiResponse); 

回答

0

https://www.dropbox.com/developers/core/api

瞭解上傳文件的URL結構https://api-content.dropbox.com/1/files_put/<root>/<path>?param=val。其中root是root相對於指定哪個路徑的根。有效值是沙盒和Dropbox。所以你錯過了你的url的根。

+0

謝謝貝司。我已經在使用該頁面進行參考。我在我放在這裏的代碼示例(oops!)中犯了一個錯字,並且錯過了根值(這是沙箱)。我將編輯原文。 – TechyGypo 2013-04-25 08:40:55

0

我設法解決它!

問題出在我構建標題的方式。它應該是這樣的:

$headers = array(
    "'Content-Type: ".mime_content_type($filePathName)."'", 
    "'Content-Length: ".filesize($filePathName)."'", 
    "Authorization: OAuth oauth_version=\"1.0\", oauth_signature_method=\"PLAINTEXT\", oauth_consumer_key=\"".DROPBOX_APP_KEY."\", oauth_token=\"".DROPBOX_OAUTH_ACCESS_TOKEN."\", oauth_signature=\"".DROPBOX_APP_SECRET."&".DROPBOX_OAUTH_ACCESS_SECRET."\"" 
); 

Content-TypeContent-Length\r\n不再結束,並正與'包圍,並且在數組中的單獨元件。

我收到了一條線索,因爲我使用了curl_getinfo函數,而http_code的值是400,這意味着請求不好。這讓我遠離被Dropbox返回的「找不到頁面」錯誤,並讓我進一步調查標題。

相關問題