Question: How to upload an image from my webserver to facebook via FB API?
I'm writing an application that retrieves images from the user's photo album, makes some modifications (e.g. adding a watermark) then send it back to photo album.
The code I use to upload the photo is as follows
<?php
include_once("api/facebook.php");
include_once("config.php");
include_once("utils.php");
include_once("bemyfans.php");
$facebook=new Facebook($api_key,$app_secret);
$facebook->require_frame();
$user=$facebook->require_login();
echo "<p>Hello <fb:name useyou='false' uid=\"$user\"/></p>";
$args = array(
'api_key' => $api_key,
'call_id'=>microtime(true),
'v'=>'1.0',
'format' => 'JSON'
);
$args['Lenna.png']="@/home/thoai/htdocs/apps/bemyfans/Lenna.png";
signRequest($args,$secret);
$ch = curl_init();
$url = 'http://api.facebook.com/restserver.php?method=photos.upload';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
if ($data = curl_exec($ch)) echo "done";
echo $data;
function signRequest(&$args, $secret){
ksort($args);
$sig = '';
foreach($args as $k => $v){
$sig .= $k . '=' . $v;
}
$sig .= $secret;
$args['sig'] = md5($sig);
}
?>
It just doesn't work. More specifically, I keep getting an "Incorrect signature" message.
What's wrong with the code???