1

I read the instructions: Upload Photo To Album with Facebook's Graph API

But although I follow the instructions, the image can't be uploaded to FB. Here is my code. Please help me.

$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);
Community
  • 1
  • 1
hoa pham
  • 11
  • 1
  • 2

1 Answers1

0

Try this out and see the result:

echo realpath("photo.jpg") 

Does it return you the correct path?

Try with /photo.jpg or ./photo

Wilk
  • 7,873
  • 9
  • 46
  • 70
Isaac
  • 36
  • 2
  • I'm trying same method to post image to fb. I checked path coming from realpath and it's correct, but still curl returns empty string. any idea? – dvdmn Jun 17 '12 at 20:42