上传照片和标记朋友

时间:2013-03-27 12:04:24

标签: facebook facebook-graph-api facebook-php-sdk

我正在尝试在用户墙上发布照片并标记朋友,但我得到了这个:

  

致命错误:未捕获OAuthException:(#324)需要上传文件   在1238行的/home/vhosts/somesite.com/src/base_facebook.php中引发

这是我的代码

<?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,
));
?>

1 个答案:

答案 0 :(得分:0)

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

realpath用于文件系统路径,不适用于URL。

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