In this post I will show how you can post a image to user’s wall and to a page’s wall. To post image to page’s wall- the user logged must be admin of the page. Suppose Zakir is user of you admin. Now you want Zakir to post a image to a page (name of the page Gift page ) Then Zakir must be admin of the Gift page other wise it wont work.
Let’s start.
First we have to have permission from user.
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET_KEY,
'cookie' => false,
));
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'offline_access,publish_stream,user_groups,user_photos,user_videos,user_status,email,manage_pages,user_photo_video_tags'
)
);
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
$permissions = $facebook->api('/me/permissions');
if(count($permissions['data'][0])<15)
$chk=1;
$user_pages = $facebook->api(array('method' => 'fql.query','query' => 'SELECT page_id,page_url,name,pic_square FROM page WHERE page_id IN (SELECT page_id FROM page_admin WHERE uid ='.$user.' )' ));
} catch (FacebookApiException $e) {
$user = null;
}
}
if (!$user or $chk==1) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
}
Now i will upload video to users wall. I am assuming you have the file path in $server_path_to_video.
$facebook->setFileUploadSupport(true);
$args = array('title' => stripslashes('video of user'));
$args['image'] = '@'.realpath($server_path_to_video);
try {
$facebook->api("/$user/videos", 'post', $args);
}catch(Exception $e){echo $e->getMessage();
}
Now we will post a video to a page. Here i am assuming you have the id of the page in $page_id and you have the file path in $server_path_to_video.
$facebook->setFileUploadSupport(true);
$accounts = $facebook->api('/me/accounts');
//print_r($accounts);
for($i=0;$accounts['data'][$i];$i++)
{
if($accounts['data'][$i]['id']==$page_id)
{
$page_access_token=$accounts['data'][$i]['access_token'];
}
}
$facebook->setAccessToken($page_access_token);
$args = array('title' => stripslashes('video to page'));
$args['image'] = '@'.realpath($server_path_to_video);
try {
$facebook->api("/{$row['page_id']}/videos", 'post', $args);
}catch(Exception $e){echo $e->getMessage();
}
Simple right?