Facebook app post on user's wall low quality image - facebook

So I have app, which post image on user's wall. Problem is that, It automatically choose App's image (Page Tab Image 111x74) and add It on user's wall (exapanded). I need to add custom image, not app's page tab image. For now my code:
$photoCaption = 'Text......';
$link = ('https://www.facebook.com/pages/mypage/1555555555?sk=app_1800000000');
# Post Data for Photos API
$post_data = array(
'message' => $photoCaption,
'link' => $link,
'caption' => 'This is captions!'
);
$apiResponse = $facebook->api('/me/feed', 'POST', $post_data);

You post photos with /me/photos, not /me/feed, hereĀ“s the information you need including example code:
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/photos

Related

How to create post with multiple images on fb api? [duplicate]

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

post on Facebook page big photo

I have read quite a few posts about posting photos on FB (fan)page but none really answer my question.
I am using a correct call to the FB SDK to post on my page as you see the last post where there is a thumbnail photo and a few pieces of text including a link.
$attachment = array('access_token' => $FB_Token, 'message' => $FB_AppMsg,'name' => $FB_AppTitle,'link' => $FB_AppURL,'description' => $FB_AppResume),'picture'=> $FB_AppImage,
'actions' => json_encode(array('name' => $FB_AppActionName,'link' => $FB_AppActionLink)));
$status = $facebook->api("/".$FB_PageName."/feed", "POST", $attachment);
Instead of a thumbnail image, I want an image of the width of 1 or 2 column (as you will see down the timeline), and a text message that can include a link to my blog on my website.
How can I achieve this easily ?

facebook post image to user wall and image store in my fan page album

Isn't possible facebook allow us from my apps post or share image to user wall and then at the same time the user image will store in my fan page album?
And suggestion and opinion how to do it? hopefully you guy able provide some code for me
step1
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'email,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown,user_photos'
)
);
step2 , 4 ,5
$file='images/'.$_FILES["file"]['name'];
if( move_uploaded_file($_FILES["file"]["tmp_name"],$file))
{
$facebook->setFileUploadSupport(true);
$post_data = array(
'name'=>$_POST['album'],
'description'=>$_POST['album']
);
$data['album'] = $facebook->api("/me/albums", 'post', $post_data);
//$file = $file_name;
$post_data = array(
"message" => $_POST['message'],
"source" => '#' . realpath($file)
);
$album_id = $data['album']['id'];
$data['photo'] = $facebook->api("/$album_id/photos", 'post', $post_data);
}
it is possible...steps
take user publish stream permissions - scope - publish_stream,user_photos
set application for uploading image..setFileUploadSupport(true);
send the image to users wall using feed api
fetch user photo
Upload it on pages' album by albums api

Facebook Posting a url to page

I use below code to post an url to facebook page as a admin but if i post an message,it is posting but it is not posting photos and url.
$args = array(
'access_token' => token,
'message' => $url
);
$wall = $facebook->api("/".$pid."/feed","post",$args);
Is there any other function that does that?
You need to add
'caption'
'link'
'picture'
variables to your array to show a picture with a caption and a link to a url.

Facebook graph API: Upload page image

Is it possible to upload an image to a facebook page as the page picture (not a photo album picture) through the graph api? And then is it possible to also define the offsets to create the miniature picture when a user writes posts as this page?
Yes below worked for me in many places
$file = '#' . realpath('path_to_image');
// Fill in your arguments.
$args = array(
'access_token' => $token,
'image' => $file,
'aid' => $albumid
);
// Send the api request.
$data = $facebook->api('/'.$pageid.'/photos', 'post', $args);