I am trying to publish post to Facebook news feed (timeline) with Graph API.
I can use Facebook standard GUI messenger to publish post and add photos to this post. But how to make this from Facebook Graph API?
I can upload images to album and try to create link on this images. But can create only 1 link.
What is the correct algorithm to publish post with more than 1 picture added to this post?
As of now it is not possible to publish one post with multiple pictures. You need to create separate posts for each one of them, or put all the images together in one with your favourite server language and post it as single picture.
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'];
According to the documentation, it is possible to do so: https://developers.facebook.com/docs/graph-api/photo-uploads#publishing-a-multi-photo-story
The gist is to:
Upload photos but mark them as "unpublished", keep the ids
Create a "post" with those "unpublihsed" photos as attachments
Hope it helps.
Related
I would like to update the like_count and comments_count for a specific instagram post with the new Facebook Instagram API. We have the post id and other data stored in our database and would only need the data of that specific post. At this point I am able to get the like and comment count via this API call:
https://graph.facebook.com/v2.12/xxxx?fields=business_discovery.username(jacqehoward){id,name,username,website,profile_picture_url,biography,followers_count,media_count,media.after(QVFIUlZA5aTR5NTE4Y24tNW90VGZAPTVBtb0NpOEFPTlNLeklmVTEtUDZAfVnE0YnBhUVNOQ3BDaktzNHJBTENhTmVYLUV2SGJPZAVAxZA09hQ2NhUGdnUGFjMTNn){id,caption,comments_count,like_count,media_type,media_url,owner,timestamp}}
After a while new posts are added to the account and you would need to go through all of the posts to find them again and to be able to get the like & comments count. In the old Instagram API you could get like and comment count per media. In the new Instagram API you are only able to get reach or "engagement" which is a combination of likes and comments while I want to have them separately.
https://developers.facebook.com/docs/instagram-api/insights
Anyone who has an idea how to add like count and comments count to the insight endpoint call?
Second question: If an instagram user with a private instagram account connects with your app how do you get the Facebook instagram ID so you can collect the posts on their timeline?
Since FQL is deprecated from 2.1 onwards.Is there any way to get all the posts that a page is tagged in using Graph API.
tried {page_id}/tagged but it shows only the page's posts not the posts that a page was tagged.
I want to query the posts using graph API by a user on their own wall that tags the page.is there any way to do that?
isn't this a functionality of the Public Feed API which Accessing it is restricted to a limited set of media publishers and usage requires prior approval by Facebook. Applications to the API are not open at this time.
I would like to publish more than one photo on Page Timeline, but do not see any way how to manage it. I can publish only one photo on Page Timeline or album.
Is there any chance how to upload multiple photos into Page Post in help with Graph API?
Edit: As found out, not worked successfully, because there were changes. More info here...
This is an old post, and I don't know if this method could work back in 2014, but in 2017 it's working. Unfortunately there's no way to create the post in one FB query, but there's a trick.
Step 1
Batch upload the images in silent mode, which means there will be no post on the timeline, just pure upload.
For this you have to use
'published' => false,
in the parameters, and
/me/photos
as the URL.
Step 2
After each upload FB will give you back the ID of the uploaded image. Grab those into an array:
$resparr[] = $graphNode['id'];
Step 3
After the uploads you will have an array of the image IDs. Let's format them for the FB post:
$phc = 0;
foreach ($resparr as $pid) {
$linkData['attached_media['.$phc.']'] = (object)array('media_fbid'=>$pid);
$phc++;
}
Step 4
Make an other call to the API, but this time the URL should be
/me/feed
This will create a public post which contains the images.
(You need a page access token for this to post onto a page, or a user access token to post your wall.)
More info # Faceook Developers.
Is it possible to get and to change the new porfile cover (mine or my friends' profil cover) with the sdk php or JS ?
It is possible to get the Facebook's user cover image using the Graph API. You have to add 'fields=cover' to the user request. The response is an array of fields id, source, and offset_y. You need an access token for this.
You cannot update the cover photo using the API, only retrieve it.
http://graph.facebook.com/[USER_ID]?fields=cover
It's still not possible with the current APIs exposed by Facebook.
Most of the examples and tutorials I have found for the Facebook SDK are for publishing to user accounts.
As someone who has used the Facebook PHP SDK but not the Javascript SDK, I can't find an example or tutorial for the following:
User clicks FB connect button
Popup window shows manageable Fan Pages
User chooses a Page which they'd like my website to manage
My website gets the ID of the chosen Page
With my website I'm not looking to post information to the admin's Fan Page, but rather just get the ID of the Page they want to use with my site. Thanks to the PHP SDK, I already have a method of pulling all the information from the admin's Fan Page that I need.
Is there such a guide?
You can use the graph to get '/me/accounts' which will list all of the apps/pages that the user administrates. You will need to create your own selection pop up for step 2 and 3, using the data from the response object as the values to submit back to your site in step 4.
Try something like this:
FB.login(function (response){
FB.api('/me/accounts',function(apiresponse){
var data=apiresponse['data'];
var ids = new Array();
for(var i=0; i<data.length; i++){
ids[i]=data[i].id;
}
console.log(ids);
});
},{scope:'manage_pages'});