Post video on a fan page on facebook using php-sdk - php

I am having videos uploaded by users on my live site. I have created an admin panel where the admin reviews all the videos and if he wish that video to be posted on facebook then he has a button as Post to Wall infront of each video.
I have seen this tutorial but still unable to post videos on a fan page. I also found one more tutorial but according to this we can upload video only if it is on our local machine.
My problem is I want to upload video which is on my server not on my local machine. How can I achieve this? Please help.
Code for upload on fb:
$message = array('source' => 'http://bizmoapps.com/icstories/uploads/video/52e113c822271vid-20130707-wa0000.mp4');
$url = '/' . $_POST['pageid'] . '/photos';
$result = $fb->api($url, 'POST', $message);
if ($result) {
echo 'Data posted successfully';
}

Related

Facebook Graph API: Publish post with multiple videos and photos

I try to publish a post with multiple videos and photos by using the PHP SDK. I uploaded videos and photos using batch request and got the id. Then I pass the media ids along with post data using attached_media. Things work fine for single or multiple photos. But not for a single video or multiple videos. I got this error: "Graph returned an error: (#10) Application does not have permission for this action" whenever ids of videos are included in attached_media.
Here is the code that I used:
$fb = $this->init(); try{ // Returns a Facebook\FacebookResponse object
$publishData = [ 'message' => $post['content']];
if(count($media_ids) > 0){
$publishData ['attached_media'] = [];
foreach($media_ids as $key => $media_id){
array_push($publishData['attached_media'],'{"media_fbid":"' . $media_id . '"}');
}
}
$response = $fb->post(
'/me/feed',$publishData
,
$accessToken
);
}
catch(FacebookResponseException $e){
echo 'Graph returned an error: ' . $e->getMessage();
echo $e->getTraceAsString();
exit;
}
catch(FacebookSDKException $e){
echo 'Facebook SDK returned an error: ' . $e->getMessage();
echo $e->getTraceAsString();
exit;
}
$graphNode = $response->getGraphNode();
Is there anyway to solve this. Thank you.
The truth is that you can't mix photos and videos. Facebook's API doesn't allow that. You can make:
A post containing video + text (description)
A post containing multiple photos + text
To make a video post you have to hit
POST https://graph-video.facebook.com/v10.0/<page id>/videos?file_url=<public file URL>&access_token=<your access token>&published=true&description=<text>
The file_url and description should be URL encoded.
To post multiple photos you first do the photo "uploading" and as a result you'll have ids. Those ids you set to attached_media param.
Getting photo ids:
POST https://graph.facebook.com/<page id>/photos?url=<public file URL>&access_token=<access token>&published=false
Notice the published=false. That's important. Without that you'll make a page post containing a single photo.
And finally making the actual page post:
POST https://graph.facebook.com/<page id>/feed?message=<text>&access_token=<access token>&attached_media[0]={"media_fbid":"<id>"}&attached_media[1]={"media_fbid":"<id>"}
P.S.
This approach assumes that you have your content uploaded somewhere else and you have public URLs where this content is available. If you have the raw files and you want to upload them to Facebook then you have to follow another approach.
I know its been a while but I was having the same problem and it's 2020...
The only way I was able to show the video in the timeline of a page was using the following Facebook documentation that covers uploading & posting a video to a user's timeline with the Facebook SDK for PHP.
https://developers.facebook.com/docs/php/howto/example_upload_video
It's clearly not the best approach but at least the video appears in the timeline with some title and description.
$data =
[
'title' => 'Your title',
'description' => 'Your description'
];
$response = $fb->uploadVideo($pageId, $videoUrl, $data, $token);
Note: the videoUrlmust be a relative path as the FacebookFile class uses functions like filesize.
Facebook doesn't directly allow to publish post with multiple videos and photos on the business page. However, it is possible on a personal page so as an alternate solution you can create a post on a personal page and share it on the business page.
Check this video for more information: https://www.youtube.com/watch?v=AoK_1S71q1o

Facebook event api to upload cover image

i have working for facebook event creation if we set profile picture for the event which is working fine but while uploading cover image which is not working , " it throws #200 permission error" below is the code i have used from the post link Facebook PHP SDK: Upload Event Cover Photo
$cover['cover_url'] = 'http://urlofimage';
$eid = 'xxxxxxxxxxxxxxxxxxxxxx';
$facebook->setFileUploadSupport(true);
$eventUpdate = $facebook->api( "/" . $eid, 'post', $cover );
but its not worked still, can someone please help me.
OR please mention if its possible or not
i use this code and its working fine .
$data = array(
"access_token"=>$fb_oauth_token,
"cover_url" => $image_full,
);
remember to use the accesstoken for posting etc.
thanks

facebook api post to wall

I currently am able to post to a users wall however I would like the post to give a preview since what im posting is a link...
To explain myself better If i was to log into my facebook account and copy a link and paste it to my wall it displays an audio player (all the meta data is already configured, tested and working) however, using code to post this same link it doesnt show the audio player instead it only shows the link to click on. Is there a way i can make facebook display the audio player...?
Heres the code im using to post:
$fbResult = $facebook->api(
'/' . $userId . '/feed/',
'post',
array('access_token' => $access_token, 'message' => $url)
);
Thanks in advance for the help!
I’m assuming you’re posting the URL as part of your message parameter?
Do it by explicitly using the link parameter for the URL.
https://developers.facebook.com/docs/reference/api/user/#links

Post image to Facebook fan page with PHP SDK

I am trying to upload a image to my fan pages wall using the PHP SDK, and also let other people upload pics to the page.
Here is what I have thus far,
PHP:
$img = realpath($y);
$facebook->setFileUploadSupport("http://" . $_SERVER['SERVER_NAME']);
$photo = $facebook->api('/FAN_PAGE_ALBUM_ID/photos', 'POST',
array(
'access_token' => $token,
'source' => '#' . $img,
'message' => 'This photo came from my app.'
)
);
When I try that nothing happens, even though I used a similar method to post to the fan pages wall, which worked fine, I also have the appropriate permissions, as far as I know... status_update,publish_stream,user_photos,offline_access ??
Any reason why this could be happening?
For you to be able to upload pictures to a page you are an administrator of, you would most likely need manage_pages permissions. I'm not sure you can have users upload pictures to a fan page from the graph api, although they can from the website so they should be able to.
You need this permission: manage_pages.

Facebook Photo Upload into Album on Fan Page failed

I have written an Application what posts Photos on a FanPage into a Specific Album long time ago.
Now I didn't used for a half year. Now I had to set up the Application again and grant the extended Permissions to the Fan Page (streamm_publish) again.
But now I've a Problem, I'm using the old REST API what now gives me the error: An unknown error ocurred with the error code 1.
Then I tried to post throught the Facebook Graph api.
I tried to make a call to the Api /pageid/albumid/photos what's not working(Unknown path components)
I tried to makea a call to /albumid_from_my_page/photos then the Photos were posted to my profile
I tried to upload it to /pageid/photos what is the same as the one above
But the code fpr the REST Api worked well, what's the problem there, and why the new Graph Api isn't working how she should?(BUG?)
To post a photo to an album, this is the code:
$post_data = array(
"message" => "My photo caption",
"source" => '#' . realpath($file)
);
$album_id = "XXXXX";
$facebook->api("/$album_id/photos", 'post', $post_data);
Now I suppose to interact with the page albums you need a page access_token added to your $post_data array, for this check this answer.
You need take ACCESS_TOKEN page...
try:
http://graph.facebook.com/me/accounts?access_token= GET THIS TOKEN USING GRAPH API... OR MAKE USING the getAccessToken()...
and will see all pages and aplications that u have, find just application for this case and COPY TOKEN... and damn!!!
It's possible to see this token thought GRAPH API EXPLORER...
regards.

Categories