2011-09-05 69 views
1

我看說明書:Upload Photo To Album with Facebook's Graph API上傳圖片至Facebook通過使用curl PHP

不過,雖然我按照說明,該圖像不能被上傳到FB。這是我的代碼。請幫幫我。

$graph_url = "https://graph.facebook.com/". $album_id . "/photos?access_token=" . $access_token; 

$ch = curl_init(); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_VERBOSE, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_URL, $post_url); 

$post_array = array(
     "source" =>"@". realpath("photo.jpg"), 
     "message"=>"Upload " . date('Y-m-d h:i:s') 
    ); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array); 
    $response = curl_exec($ch); 
$graph_url = "https://graph.facebook.com/". $album_id . "/photos?access_token=" . $access_token; 

$ch = curl_init(); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_VERBOSE, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_URL, $post_url); 

$post_array = array(
     "source" =>"@". realpath("photo.jpg"), 
     "message"=>"Upload " . date('Y-m-d h:i:s') 
    ); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array); 
    $response = curl_exec($ch); 
+2

嘗試 「的形象不能被上傳到FB」。爲什麼不?你有任何錯誤? – CodeCaster

+0

你設法做到了嗎? – user3697768

回答

0

試試這個,看看結果:

echo realpath("photo.jpg") 

是否返回你正確的路徑?

/photo.jpg./photo

+0

我試圖用同樣的方法發佈圖像到fb。我檢查了來自實際路徑的路徑,它是正確的,但仍然會返回空字符串。任何想法? – dvdmn