2013-06-25 17 views
0

我在Facebook上有一個粉絲頁面(或品牌頁面)。我創建了一個PHP應用程序,我想在此品牌頁面上發佈消息,但不是以我自己的用戶名稱,而是以此品牌名稱。所以基本上我想以這個品牌的名義,通過PHP寫。張貼到Facebook作爲品牌頁面 - PHP

我有以下代碼:

//This is the Page ID of the branding page 
    $post_url = '/'.$userPageId.'/feed'; 

    // posts message on page feed 
    $msg_body['message'] = $userMessage; 

    if (!empty($userLink)) { 
     $msg_body['link'] = $userLink; 
    } 
    if (!empty($userDescr)) { 
     $msg_body['description'] = $userDescr; 
    } 
    if (!empty($userPic)) { 
     $msg_body['picture'] = $userPic; 
    } 

    try { 
     $postResult = $facebook->api($post_url, 'post', $msg_body); 
    } catch (FacebookApiException $e) { 
    echo $e->getMessage(); 
    } 

代碼放置在品牌頁面上的消息,但是從我自己的賬戶。任何想法如何我可以寫信,如果消息來自品牌本身?

在此先感謝!

+0

是否經由它有一個公開會議,Facebook的瀏覽器中執行這個腳本?你是否以你自己的身份登錄? –

+0

通過瀏覽器。我以自己的身份登錄。當我切換到這個品牌頁面時,PHP應用程序要求我切換到自己 –

+0

您是否要求'manage_page'權限? –

回答

1

我終於設法解決它。問題是我沒有通過頁面訪問令牌。下面的代碼工作得很好,也修復了字符編碼問題發佈ASCII擴展的跡象,當我有:

$userPageId  = $_POST["userpages"]; 
$userMessage = $_POST["message"]; 
$userLink = $_POST["link"]; 
$userDescr = $_POST["description"]; 
$userPic = $_POST["picture"]; 
$access_token = $_POST["page_access_token"]; 
$userCaption = $_POST["caption"]; 

//HTTP POST request to PAGE_ID/feed with the publish_stream 
$post_url = '/'.$userPageId.'/feed'; 

// posts message on page feed 
$userMessage = utf8_encode (stripslashes($userMessage)); 
$userMessage = iconv("UTF-8", "UTF-8//TRANSLIT", $userMessage); 

$userCaption = utf8_encode (stripslashes($userCaption)); 
$userCaption = iconv("UTF-8", "UTF-8//TRANSLIT", $userCaption); 

$userDescr = utf8_encode (stripslashes($userDescr)); 
$userDescr = iconv("UTF-8", "UTF-8//TRANSLIT", $userDescr);  

$msg_body['message'] = $userMessage; 
$msg_body['access_token'] = $access_token; 

if (!empty($userLink)) { 
    $msg_body['link'] = $userLink; 
} 
if (!empty($userDescr)) { 
    $msg_body['description'] = $userDescr; 
} 
if (!empty($userPic)) { 
    $msg_body['picture'] = $userPic; 
} 
if (!empty($userCaption)) { 
    $msg_body['caption'] = $userCaption; 
} 

if ($fbuser) { 
    try { 
    $postResult = $facebook->api($post_url, 'post', $msg_body); 
    } 
     catch (FacebookApiException $e) { 
    echo $e->getMessage(); 
    } 
} 
相關問題