I'm trying to upload a custom thumbnail with a link post using the php sdk but it is showing the error
(#100)Invalid File. Expected file of one of the following types: image/jpg, image/jpeg, image/gif, image/png
the uploaded file works ok for posting a photo so I know the file is ok, what could be the issue here when trying to post as a link?
on this page https://developers.facebook.com/docs/reference/ads-api/link_post_custom_image/
it shows it should work. I've tried ignoring the uploaded file and hard code a path to a known existing image but it still shows the error when trying to post a link with the 'thumbnail' parameter
I've tried copying the file to local first and then using that path but still it shows the error
if I leave off the thumbnail and picture parameters, facebook grabs it's own image for the thumbnail so the posting function works, just not with the thumbnail parameter
here is a sample bit of code the html form
<form id="form" method="post" action="newpost.php" enctype="multipart/form-data">
<div id="container">
<div id="content">
<div id="fbpages">
<?php
foreach($c->accounts as $page){
echo '<li title="Post to '.$page->name.'" class="fbpage" pageid="'.$page->id.'"><img src="http://graph.facebook.com/'.$page->id.'/picture" width="37" height="37"/></li>';
}
echo '<li title="post to personal timeline" class="fbpage" pageid="personal"><img src="http://graph.facebook.com/'.$user.'/picture" width="37" height="37"/></li>';
echo '<li title="Post to Wordpress" class="fbpage" pageid="wordpress"><img src="images/wordpress-logo.png"/></li>';
?>
<input type="hidden" name="fbpages" />
</div>
<div id="fields">
<div id="text-1">
<textarea id="message" name="message"><?php if($c->alt){ echo $c->alt;}?></textarea>
</div>
<div id="image">
<img src="<?php echo $c->src;?>" />
<br><input name="nopicture" value="yes" type="checkbox"/>No Picture (let facebook choose)
<input type="file" name="file"/>
</div>
<div id="text-2">
<p>Name<br><input type="text" id="name" name="name" placeholder="name" value="<?php echo $c->title;?>"/></p>
<p>Link<br><input type="text" id="link" name="link" placeholder="link" value="<?php echo $c->foundpage;?>"/></p>
<?php $da = parse_url($c->foundpage); $caption = $da['host']; ?>
<p>Caption<br><input type="text" id="caption" name="caption" placeholder="caption" value="<?php echo $caption;?>"/></p>
<p>Description<br><textarea id="description" name="description" placeholder="description"><?php echo $c->description ? $c->description : $c->alt;?></textarea></p>
</div>
</div>
<div id="controls">
<div id="leftcontrols">
<p><strong>Auto Comment</strong><p>
<input type="checkbox" id="docomment" name="docomment" value="yes" />
<textarea id="comment" name="comment" rows="3" placeholder="Comment text"><?php echo 'Found at '.$c->foundpage;?></textarea>
</p>
</div>
<div id="rightcontrols">
<strong>Select type of post:</strong><br />
<select id="type" name="type">
<option value="photo">Post a Photo</option>
<option value="link">Post a Link</option>
<option value="status">Post a Status</option>
</select>
<p class="controls">
<strong>Time and Date to post</strong><br />
<input type="text" id="date" name="date" value="<?php echo date('d/m/Y H:i');?>" placeholder="date"/>
<br><button id="now">Now</button> <button id="plus6">+6 Hours</button>
</div>
</p>
<input type="submit" name="clear" value="clear"/>
<p id="submit">
<input type="submit" name="submit" value="Submit"/>
</p>
</div>
</div>
</div>
the function that posts as a photo that works fine
if(!empty($_FILES["file"]["tmp_name"])){
$facebook->setFileUploadSupport(true);
$c['image'] = '@'.$_FILES["file"]["tmp_name"];
}
if($type == 'photo'){
// build args
$args = array(
'message' => $message,
'published'=>$scheduledpost ? 0 : 1,
'no_story' => 0,
'access_token' => $accesstoken
);
if(isset($c['image'])){
$args['image'] = $c['image'];
} else {
$args['url'] = $c['src'];
}
if($scheduledpost){
$args['scheduled_publish_time'] = $timetopost;
}
try {
$photo = $facebook->api($pageid . '/photos', 'post', $args);
// post comment if sent
if( is_array( $photo ) && !empty( $photo['id'] ) ){
///photo posted, make comment with link
if(isset($_POST['docomment']) && $_POST['docomment'] == 'yes'){
$commentmessage = 'Found at '.$_POST['comment'];
try{
$comment = $facebook ->api('/'.$photo['id'].'/comments',
'post',
array(
'access_token' => $accesstoken,
'message' => $commentmessage,
)
);
} catch (FacebookApiException $e){
echo '<h2>Had an error updating the comment '.$e->getMessage();
}
}
}
}catch(FacebookApiException $e){
echo "<h2>Error</h2>can't post photo. It must be protected from being shared. <script>setTimeout(\"self.close();\",2500);</script>";
exit;
}
but when I try to post a link using the same uploaded file , it shows the error
if($type == 'link'){
//debugbreak();
$args = array(
'access_token' => $accesstoken,
'message' => $message,
'name' => $_REQUEST['name'],
'link' => $_REQUEST['link'],
'caption'=>$_REQUEST['caption'],
'description' => $_REQUEST['description'],
'picture'=> $c['src'],
'published'=> 1
);
if(isset($_POST['nopicture'])){
unset($args['picture']);
}
if(isset($c['image'])){
$args['thumbnail'] = $c['image'];
}
if($scheduledpost){
$args['scheduled_publish_time'] = $timetopost;
$args['published'] = 0 ;
}
try{
$link = $facebook->api('/'.$pageid.'/feed','POST',$args);
if( is_array( $link ) && !empty( $link['id'] ) ){
///photo posted, make comment with link
if(isset($_POST['docomment']) && $_POST['docomment'] == 'yes'){
$commentmessage = 'Found at '.$_POST['comment'];
try{
$comment = $facebook ->api('/'.$link['id'].'/comments',
'post',
array(
'access_token' => $accesstoken,
'message' => $commentmessage,
)
);
} catch (FacebookApiException $e){
echo '<h2>Had an error updating the comment '.$e->getMessage();
}
}
}
} catch(FacebookApiException $e){
echo "<h2>Error</h2>can't post link.<script>setTimeout(\"self.close();\",2500);</script>";
exit;
}
update
I ended up sending the image to facebook as a nostory and then get the source from the info and use that as the src for the link
if(isset($c['image'])){
$targs = array(
'published'=> 0,
'no_story' => 0,
'access_token' => $accesstoken,
'image'=>$c['image']
);
//try temporary photo
$picture = $facebook->api($pageid . '/photos', 'post', $targs);
if($picture){
// get info about picture and set src to source
$picinfo = $facebook->api($picture['id']);
$args['picture'] = $picinfo['source'];
$c['src'] = $args['picture'];
}
}