$fb = new Facebook(array('appId'=>$appId, 'secret'=>$secret));
$fbuser = $fb->getUser();
if($fbuser){
if(isset($_POST['submit1']))
{
$message=$_POST['messsage'];
$desc=$_POST['desc'];
$link=$_POST['link'];
if($_FILES['uploadedfile']['type']=='image/jpg' || $_FILES['uploadedfile']['type']=='image/jpeg' || $_FILES['uploadedfile']['type'] == 'image/gif' || $_FILES['uploadedfile']['type'] == 'image/png')
{
$new_file_name=$random_digit.$_FILES['uploadedfile']['name'];
// Where the file is going to be placed
$target_path = "Images/".$new_file_name;
$SITE_URL="http://shreehariinfotech.com/post-to-fb-wall/";
$FullPath = $SITE_URL.$target_path;
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
//$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
$page_id = "624998370883506";
//$page_access_token = "";
$result = $fb->api("/me/accounts");
// loop trough all your pages and find the right one
if( !empty($result['data']) )
{
foreach($result["data"] as $page)
{
if($page["id"] == $page_id)
{
$page_access_token = $page["access_token"];
break;
}
}
}
else
{
echo "AN ERROR OCCURED: could not get the access_token. Please verify the page ID ".$page_id." exists.";
}
// set the facebook active facebook access token as the one we just fetch
$fb->setAccessToken($page_access_token);
// Now try to post on page's wall
try{
$message = array(
'message' =>$message,
'picture' =>$FullPath,
'description' => $desc,
'link' => $link
);
$result = $fb->api('/'.$page_id.'/feed','POST',$message);
if($result){
echo 'Successfully posted to Facebook Wall...';
}
}catch(FacebookApiException $e){
echo $e->getMessage();
}
}
}
}
}
else{
$fbloginurl = $fb->getLoginUrl(array('redirect-uri'=>$returnurl, 'scope'=>$permissions));
echo '<a href="'.$fbloginurl.'">Login with Facebook</a>';
}
?>
<html>
<body>
<div style="align:center;">
<h1>Post To Hindi Dictionary</h1>
<div style="alignment-adjust:central">
<table cellpadding="2" cellspacing="2" border="1">
<form name="frm" id="frm" action="feed_page.php" method="post" enctype="multipart/form-data">
<label>Message</label>
<input type="text" name="messsage" id="message"/><br/>
<label>Image</label>
<input type="file" name="uploadedfile" id="uploadedfile"/><br/>
<label>Description</label>
<textarea name="desc" id="desc"></textarea><br/>
<label>Link</label>
<input type="text" name="link" id="link"/><br/>
<input type="submit" name="submit1" id="submit1" value="Submit"/><br/>
</form>
</table>
</div>
</div>
</body>
</html>
No comments :
Post a Comment