我希望我们的Facebook页面的粉丝能够将图像发布到特定的相册。虽然该应用程序能够将图像上传到用户时间线,但该应用程序无法将其发布到粉丝页面中的相册(公司的Facebook页面)。出了什么问题,或者我如何更改代码以便跟踪错误。
在之前的尝试中,我能够使用类似的脚本和永不过期的令牌将图像发布到粉丝页面的墙上,然后应用程序发布了它,我希望看到用户名。
<?php
require 'facebook.php';
$app_id = "xxx";
$app_secret = "xxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$canvas_page = "http://apps.facebook.com/xxx/";
$auth_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page)."&scope=publish_stream";
$signed_request = $_REQUEST["signed_request"];
if(isset($_FILES["source"]["name"]))
{
try {
$facebook->setFileUploadSupport(true);
$response = $facebook->api(
'/ALBUMID/photos/',
'post',
array(
'message' => $_POST['message'],
'source' => '@'.$_FILES["source"]["tmp_name"],
'access_token' => 'xxx'
)
);
}
catch (FacebookApiException $e) {
error_log('Could not post image to Facebook.');
}
}
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
echo ("Welcome User: " . $data["user_id"]);
};
$signed_request = $facebook->getSignedRequest();
$user = $facebook->getUser();
$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];
echo "<br>user id = $user";
echo "<br>page id = $page_id";
echo "<br>page admin = $page_admin";
echo "<br>like status = $like_status";
echo "<br>country = $country";
echo "<br>locale = $locale";
if ($like_status) {
?>
<div id="like">
You like us.
<form enctype="multipart/form-data" action=" " method="POST">
Please choose a photo:
<input name="source" type="file"><br/><br/>
Say something about this photo:
<input name="message"
type="text" value=""><br/><br/>
<input type="submit" value="Upload" class="btn btn-primary"/><br/>
</form>
<?php
if(isset($response))
{
echo "Image Uploaded. <a href='http://facebook.com/{$response['id']}' target='_blank'>Click here to view</a>";
}
?>
</div>
<?php
}
else {
?>
<div id="niet_leuk">
You don't like us.
</div>
<?php
}
?>
答案 0 :(得分:0)
这是facebook opengraph的一个已知错误。您可以在此处查看详细信息:https://developers.facebook.com/bugs/246002638848837/
它被标记为低优先级,所以我不希望很快就能修复。
现在,您只能将图像作为页面管理员或页面本身发布到非用户页面。