2013-04-02 98 views
1

我希望我們Facebook頁面的粉絲能夠將圖像發佈到特定專輯。雖然該應用能夠將圖像上傳到用戶時間軸,但該應用無法將其發佈到粉絲專頁(公司的Facebook頁面)。什麼是錯的,或者我該如何更改代碼才能追蹤錯誤。將圖片上傳到Facebook粉絲頁面

在之前的嘗試中,我能夠使用類似的腳本和永不過期的令牌將圖像發佈到fanpage的牆上,但隨後應用程序發佈了它,並且我想查看用戶名。

<?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

這是一個已知的問題與facebook的opengraph。你可以在這裏看到它的細節:https://developers.facebook.com/bugs/246002638848837/

它被標記爲低優先級,所以我不會期待很快修復。

所以現在,您只能將圖像作爲頁面管理員或作爲頁面本身發佈到非用戶頁面。

+0

似乎現在已經修復 – b1r3k