Uploading image to Facebook by using Curl PHP
I read the instructions: Upload Photo To Album with Facebook's Graph API
But although I follow the instructions, the i开发者_StackOverflow社区mage 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);
Try this out and see the result:
echo realpath("photo.jpg")
Does it return you the correct path?
Try with /photo.jpg
or ./photo
精彩评论