2013-12-20 83 views
0

我是Facebook粉絲頁面的管理員,我需要以管理員身份發佈圖片。當我使用這段代碼時,它會在我自己的Facebook牆上發帖。我有應用程序的管理權限。 有什麼想法?發佈到Facebook粉絲頁面不屬於我自己的Facebook牆壁

<?php 
    $album_id ='9543045'; 
    $access_token='W4997qoxbdFGLZA1d8a7JhoNoKxZBcNdFcdUXgDXa7k7oeFvKBIZA6OHf81pZAyV5nCAZD'; 
    $file= '/Users/bazinga/Desktop/banner1.png'; 
    $args = array(
     'message' => urlencode('Hello'), 
     'description' => urlencode('World'), 
     'access_token' => urlencode($access_token) 
    ); 
    $args[basename($file)] = '@' . realpath($file); 
    $ch = curl_init(); 
    $url = 'https://graph.facebook.com/'.$album_id.'/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)); 

回答

0

您需要頁面訪問令牌上傳代網頁管理員的照片。

您可以通過https://graph.facebook.com/me/accounts?access_token=USER_ACCESS_TOKEN

獲得你的頁面訪問令牌的另一種方式,如果你已經知道的頁面ID,那麼你可以要求

https://graph.facebook.com/PAGE_ID?fields=access_token&access_token=USER_ACCESS_TOKEN

此外,還要確保您的要求status_update如我回答why does posting to facebook page yield "user hasn't authorized the application"

最後一件事,我認爲描述access_token在您的$ args數組中是多餘的。

相關問題