It is possible to post single images to multiple pages and multiple images to single page but its not possible to post multiple images to multiple pages
Here I am taking user connected pages ie. single/multiple pages as $pages
To post single image on multiple pages i commented few code below, and given published = true
foreach ($pages as $key => $page) {
$page_id = $page['page_id']
$page_access_token = $page['page_access_token']
$all_media = PostMedia::where('post_id',$post_id)->get();
$medias = [];
foreach ($all_media as $one_media) {
$medias[] = public_path('/images/social/'. $one_media->media_local );
}
foreach($medias as $image){
try {
$response = $facebook->post("/$page_id/photos", [
'message' => $message,
'source' => $facebook->fileToUpload($image),
'published' => 'true'
], $page_access_token);
} catch(Facebook\Exceptions\FacebookSDKException $e) {
$errors[]= 'Error: ' . $e->getMessage();
}
$graphNode = $response->getGraphNode();
//$post_images[]= $graphNode['id'];
}
// foreach ($post_images as $key => $post_image) {
// $attachMedia[$key] = ['media_fbid' => $post_image];
// }
// try {
// $response = $facebook->post("/$page_id/feed",
// [
// 'message' => $message,
// 'attached_media' => $attachMedia
// ],$page_access_token);
// } catch(Facebook\Exceptions\FacebookSDKException $e) {
// $errors[]= 'Error: ' . $e->getMessage();
// }
// $post = json_decode($response->getBody());
}
But to post multiple images on multiple pages I'm facing difficulty because for one page_id I'm getting multiple attached media id's which is in loop.
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2GZzt1w
via IFTTT
Aucun commentaire:
Enregistrer un commentaire