facebook php post photo - IT NEWS


Programming PHP tutorials for beginners. Technology and product reviews.

Monday, May 22, 2017

facebook php post photo


facebook php post photo

PHP script for posting to Facebook image/photo to page with Graph API. URL link with (PNG, JPG) file from your or other web-site.
Type page Album ID if you want post image to page Album only. If you type Page ID, photo/image will be posted to Facebook page feed.

$access_token = "*******"; // token
$page_id = "******"; // page id, or user id, type Album ID if you want post image to Album only

$url = "https://graph.facebook.com/$page_id/photos";

$data = array(
'access_token' => $access_token,
'caption' => "test photo",
'url' => "http://lh5.googleusercontent.com/-QfoXx7AsqCU/AAAAAAAAAAI/AAAAAAAAANg/dvsM-z4RF-g/s512-c/photo.jpg",

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
curl_close ($ch);
print_r ($result);

You will see post id and image id with successful request.

Photo was saved in album.


No comments:

Post a Comment