Now I posting a single photo to wall like this:
$response = $facebook->api("/$group_id/photos", "POST", array(
'access_token=' => $access_token,
'message' => 'This is a test message',
'url' => 'http://d24w6bsrhbeh9d.cloudfront.net/photo/agydwb6_460s.jpg',
)
);
It works fine, but can I somehow post a multiple photos, something like this:
You can now publish multiple images in a single post to your feed or page:
For each photo in the story, upload it unpublished using the {user-id}/photos endpoint with the argument published=false.
You'll get an ID for each photo you upload like this:
{
"id": "10153677042736789"
}
Publish a multi-photo story using the {user-id}/feed endpoint and using the ids returned by uploading a photo
$response = $facebook->api("/me/feed", 'POST',
array(
'access_token=' => $access_token,
'message' => 'Testing multi-photo post!',
'attached_media[0]' => '{"media_fbid":"1002088839996"}',
'attached_media[1]' => '{"media_fbid":"1002088840149"}'
)
);
Source: Publishing a multi-photo story
You can make batch requests as mentioned here: https://stackoverflow.com/a/11025457/1343690
But its simple to loop through your images and publish them directly.
foreach($photos as $photo)
{
//publish photo
}
Edit: (regarding grouping of photos on wall)
This grouping is done by facebook automatically if some photos are uploaded into the same album.
Currently you cannot create an album in a group via Graph API - it is not supported (as of now), see this bug.
But you can do this - create an album manually, then get the album_id by-
\GET /{group-id}/albums, then use the the code with album_id instead of group_id-
foreach($photos as $photo){
$facebook->api("/{album-id}/photos", "POST", array(
'access_token=' => $access_token,
'name' => 'This is a test message',
'url' => $photo
)
);
}
I've tested it, see the result-
Actually you can upload a multi story photo(I did it using Graph Api and PHP) but the problem comes if you need scheduled this post.Your post is schedule but also it shows on the page's feed.
P.S. I'm using Graph Api v2.9
PHP Code
$endpoint = "/".$page_id."/photos";
foreach ($multiple_photos as $file_url):
array_push($photos, $fb->request('POST',$endpoint,['url' =>$file_url,'published' => FALSE,]));
endforeach;
$uploaded_photos = $fb->sendBatchRequest($photos, $page_access_token);
foreach ($uploaded_photos as $photo):
array_push($data_post['attached_media'], '{"media_fbid":"'.$photo->getDecodedBody()['id'].'"}');
endforeach;
$data_post['message'] = $linkData['caption'];
$data_post['published'] = FALSE;
$data_post['scheduled_publish_time'] = $scheduled_publish_time;
$response = $fb->sendRequest('POST', "/".$page_id."/feed", $data_post, $page_access_token);
$post_id = $cresponse->getGraphNode()['id'];
You will need to upload each photo first with published state to false, and then use the ID's of the unpublished photos to the /me/feed endpoint to schedule the photo. The schedule needs to be within the 24 hours from the time the photos are uploaded as facebook deletes all unpublished photos in 24 hours.
Ref:
https://developers.facebook.com/docs/graph-api/photo-uploads/
There is no way to publish more than one photo in the same graph API call.
See documentation: https://developers.facebook.com/docs/graph-api/reference/user/photos
Related
I am using PHP SDK to upload videos to my DailyMotion channel, but i don't understand how this work.
I do this:
// Temporarily upload a file on Dailymotion' servers
// This does not create a video, it only offers you a public URL to work with.
$url = $api->uploadFile($videoPath);
try {
// More fields may be mandatory in order to create a video.
// Please refer to the complete API reference for a list of all the required data.
$result = $api->post(
'/me/videos',
array(
'url' => $url,
'title' => $title,
'tags' => 'video,publish,api',
'published' => true,
'is_created_for_kids' => false
)
);
print_r($result);
} catch(\Exception $e) {
die('exception: ' . $e->getMessage());
}
$api->logout();
When the video is uploaded, i keep getting a message saying "Publication in progress" for days (a week now and still getting the same message).
Although i can see/watch the video just fine if i used the account it belongs to.
I'm using 'GRANT_TYPE_PASSWORD' to upload the videos to my account.
I don't want my videos to be published in search results though, i just want my app users to be able to watch them embeded.
Any help would be highly appreciated, thanks in Advance.
I'm working with facebook API that enable user to upload a photo and give caption(like instagram).
Here is my code to upload photo:
$request = (new FacebookRequest( $session, 'POST', '/me/photos', array(
'message' => $caption,
'url' => $img_url
) ) )->execute();
$result = json_decode($request->getRawResponse(), true);
If I uploaded more than one photo in the close time, the photos will be grouped in an album instead of a single post.
And facebook will return previous post id, instead of facebook post's id that I have just uploaded.
Is it normal behaviour? Does anyone know how to fix the photo id?
I'm reading wildly different things about tagging photos on Facebook.
One article says you can send tags=array(...tag_uid...) at the same time as you post the photo: Tagging photos on Facebook with Graph API / PHP SDK
One article said you can tag, but first you have to post to photo, and then set tags afterwards. (Can't remember the page)
One article said you can tag, but only one tag per request, so you have to iterate over the array. (Can't remember the page)
One article says you can't tag at all: https://developers.facebook.com/blog/post/371/
Does anyone know if tagging actually possible, and what is the correct way of doing it as of the current date?
You must get Photo ID firs and then tag someone on this photo
upload photo to album
$photo_details = array(
'message' => $message,
'access_token' => $token
);
$photo_details['image'] = '#' . realpath($file);
$uploaded_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
Get Photo ID
$photo_id = $uploaded_photo['id'];
set Friend ID you want to tag
$tags = array(
array('tag_uid' => $friend_id, 'x' => rand() % 100, 'y' => rand() % 100 )
);
tag friend
$facebook->api('/'.$photo_id.'/tags', 'post', array('tags'=>$tags));
It works for me, I hope this will help you
Greetings
Here's what's up:
I'm working on an app where the user or a page they administrate is tagged in their own image, however, tagging a page they administrate doesn't function, I have no trouble with the user being tagged.
Here's some code:
$tdata = array('tag_uid' => $fb_id,'x' => 0,'y' => 0);
$datatags[] = $tdata;
$attachment = array(
'access_token' => $access_token,
'tags' => $datatags
);
$attachment['image'] = '#'.realpath($image_name.);
$result = $facebook->api('/'.$album_id.'/photos', 'POST', $attachment);
$fb_id is either the ID for the user or the page. which is grabbed using /me/accounts in the Graph API
Thanks!
Per the documentation you cannot do this:
You can specify which user to tag using two methods: in the URL path
as PHOTO_ID/tags/USER_ID, or in a URL parameter as
PHOTO_ID/tags?to=USER_ID. Currently, you cannot tag a Page in a photo
using this API.
https://developers.facebook.com/docs/reference/api/photo/
I'm trying to post a photo to one of friends wall using the new graph api. For this I have the following code:
$attachment = array(
'message' => 'Posted a photo',
'source' => '#' . realpath(PATH_TO_MY_PHOTO)
);
$facebook->setFileUploadSupport(true);
$facebook->api('/'.$id_friend.'/feed?access_token='.$access_token, 'post', $attachment);
The problem is that the picture is not uploaded. I mean, it only post the message without any picture. This does not work either if I try to post on the current user wall.
Does anyone have any idea on how to achieve this ? Thanks.
p.s. I'm requesting only publish_stream permission
In order to post a poto to a users wall, as in publishing a photo and not a stream story,
you can post to here:
http://graph.facebook.com/ALBUM_ID/photos.
for more information visit facebook's graph api photo documentation.
You should replace "source" with "picture".
$imagepath='http://site.com/pic.jpg';
$attachment = array(
'message' => 'Posted a photo',
'picture' => $imagepath
);
$facebook->setFileUploadSupport(true);
$facebook->api('/'.$id_friend.'/feed?access_token='.$access_token, 'post', $attachment)
You can optionally add some more fields. for more details:
https://developers.facebook.com/docs/reference/api/post/