2013-03-27 68 views
1

我想贴在墙上用户和标签朋友的照片,但我发现这一点:上传图片和标签朋友

Fatal error: Uncaught OAuthException: (#324) Requires upload file thrown in /home/vhosts/somesite.com/src/base_facebook.php on line 1238

这是我的代码

<?php 
require_once "./src/facebook.php"; 

$app_id = "xxxxxxxx"; 
$app_secret = "xxxxxxxxxx"; 

// Init facebook api. 
$facebook = new Facebook(array(
     'appId' => $app_id, 
     'secret' => $app_secret, 
     'cookie' => true 
)); 

// Get the url to redirect for login to facebook 
// and request permission to write on the user's wall. 
$login_url = $facebook->getLoginUrl(
    array('scope' => 'publish_stream') 
); 

$loginUrl = $facebook->getLoginUrl($params); 


// If not authenticated, redirect to the facebook login dialog. 
// The $login_url will take care of redirecting back to us 
// after successful login. 
if (! $facebook->getUser()) { 
    echo <<< EOT 
<script type="text/javascript"> 
top.location.href = "$login_url"; 
</script>; 
EOT; 

    exit; 
} 

// Do the wall post. 
$args = array(
    'message' => 'Test Message', 
    'image' => '@' . realpath('http://imageurl.com'), 
    'tags' => array(
    array(
     'tag_uid'=> $friend1_uid, 
     'x'  => $x1, 
     'y'  => $y1, 
    ), 
    array(
     'tag_uid' => $friend2_uid, 
     'x'  => $x2, 
     'y'  => $y2, 
    ),/*...*/ 
    ), 
); 

$data = $facebook->api('/me/photos', 'post', $args); 

// Upload Support. 
$facebook = new Facebook(array(
    /*..*/ 
    'fileUpload' => true, 
)); 
?> 

回答

0
'image' => '@' . realpath('http://imageurl.com'), 

真实路径是文件系统路径,而不是URL。

将其更改为本地文件系统路径 - 或者,如果要从公开可用的HTTP URL上载照片,请使用参数名称url而不是source,并将URL作为值。

+0

我已将它更改为'image'=>'@'。 realpath('image.jpg'),但仍然不起作用 – 2013-03-28 13:03:58

+0

检查实时路径返回的结果。你是否在初始化Facebook课程的同时开启了文件上传功能?以后在什么地方做过? – CBroe 2013-03-28 13:13:21