I’m new to the facebook api, and i have a small issue.
I’m trying to upload a picture to an album of an user. For this i’m using a PHP script i’ve found here, on stack overflow :
$app_id = xxx;
$app_secret = "xxx";
$my_url = "http://apps.facebook.com/myapp/test.php";
$code = $_REQUEST["code"];
if(empty($code)) {
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url);
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="
. $app_secret . "&code=" . $code;
$access_token = file_get_contents($token_url);
//upload photo
$file= 'test.png';
$args = array(
'message' => 'Photo from application',
);
$args[basename($file)] = '@' . realpath($file);
print_r($args);
$ch = curl_init();
$url = 'https://graph.facebook.com/2038278/photos?access_token='.$access_token;
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);
$data = curl_exec($ch);
//returns the photo id
print_r(json_decode($data,true));
But the result is :
Array ( [message] => Photo from
application [test.png] =>
@/[mypath]/test.png ) Array ( [error]
=> Array ( [type] => OAuthException [message] => Error validating
application. ) )
What does this mean ? Do i need to have extended permissions for my app ?wich of them ?
i gave it acces to basic and user_photos
Thank you very much!
the second script
$app_id = “xxx”;
$app_secret = “xxx”;
$my_url = “http://apps.facebook.com/myapp/test.php”;
$code = $_REQUEST["code"];
if(empty($code)) {
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&scope=user_photos" ;
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="
. $app_secret . "&code=" . $code;
$access_token = file_get_contents($token_url);
$token = $access_token;
//upload photo
$file= 'test.png';
$args = array(
'message' => 'Photo from application',
);
$args[basename($file)] = '@' . realpath($file);
$ch = curl_init();
$url = 'https://graph.facebook.com/me/photos?access_token='.$token;
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);
$data = curl_exec($ch);
print_r(json_decode($data,true));
I think you need your application to ask for the permission called
publish_stream. There is also another permission calledphoto_upload, but as I understand that is considered old (but may still work)