2012-07-11 46 views
0

我看了幾個有關此錯誤消息的stackoverflow帖子,但沒有人爲我工作。使用Facebook PHP SDK:未捕獲CurlException:26:創建formpost dat失敗

我要上傳照片至Facebook:

public function uploadPhoto($path){ 
    $photoSettings = array(
     'access_token'=> $this->facebook->getAccessToken(), 
     'name' => 'uploaded foto', 
     'source' => '@' . realpath($path) 
    ); 

    $photo = $this->facebook->api('me/photos','POST',$photoSettings); 
} 

當我調用這個函數,我得到了以下錯誤消息:

未捕獲CurlException:26:無法創建formpost數據

我100%確定要上傳的圖像存在(並且路徑是正確的)。

這是我的facebook初始化:(文件上傳爲true)

$this->facebook = new Facebook(array(
      'appId' => $this->config['appId'], 
      'secret' => $this->config['appSecret'], 
      'fileUpload' => true, 
      'cookie' => true 
    )); 

我真的不明白,爲什麼我得到這個錯誤,因爲我的代碼似乎是正確的。你認爲我的服務器/服務器的cURL配置可能有問題嗎?我不太瞭解cURL。

我希望你能幫助我!我期待着您的回答:-)

問候, 安德烈亞斯

回答

1

realpath($path)沒有指向實際的服務器映像位置。如果$path是圖像的完整路徑,則改爲使用'source' => '@' . $path

1
I kept getting 「CurlException: 26: failed creating formpost data」 

Here is my working code for uploading a photo from the same directory as the PHP page communicating with Facebook: 
$facebook = new Facebook(array(
'appId'  =>'*****', 
'secret'  =>'*******', 
'fileUpload' => true, 
'cookie'  => true 
)); 
$user = $facebook ->getUser(); 
if($user) 
{ 
$facebook->setFileUploadSupport(true); 
$args = array(
    'message' => 'TEst from App.', 
    'image' => '@' . realpath('awesome.jpeg') 
); 
try { 
    $data = $facebook->api('/me/photos', 'post', $args); 
} catch(FacebookApiException $e) { 
    echo "ERROR: " . $e; 
} 

} 
相關問題