2012-02-22 74 views
0

如何從我的管理頁面向我的Facebook頁面發佈普通帖子,以便將內容上傳到我的網頁?如何從我自己的管理頁面(CMS)發佈到我的Facebook牆?

因此,我從我的CMS上傳內容到我的網頁,並在我的管理頁面中顯示我上傳的內容旁邊的位置我想要一個可以將該帖子發佈到我的Facebook牆上的按鈕。作爲一個普通的職位,而不是像LIKE職位或評論職位!

回答

2

首先,您需要創建一個Facebook應用程序。 然後你會得到一個應用程序ID和一個祕密密鑰。

使用這個細節,你可以使用Facebook的PHP庫 做後期到烏爾牆壁或U可以使用下面的函數

<?php 


    function doWallPost($postName='',$postMessage='',$postLink='',$postCaption='',$postDescription='') 
    { 
    $FB_APP_ID='xxxxxxxxxxxxxxxxxxxxxxxx'; 
    $FB_APP_SECRET='xxxxxxxxxxxxxxxxxxxxxxxxxxx'; 

    $APP_RETURN_URL=((substr($_SERVER['SERVER_PROTOCOL'],0,4)=="HTTP")?"http://":"https://").$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; 

    $code = $_REQUEST["code"]; 

    if(empty($code)) 
    { 
     $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=".$FB_APP_ID."&redirect_uri=".$APP_RETURN_URL."&scope=publish_stream";     
     header("Location:$dialog_url"); 
    } 

    $token_url = "https://graph.facebook.com/oauth/access_token?client_id=".$FB_APP_ID."&redirect_uri=".urlencode($APP_RETURN_URL)."&client_secret=".$FB_APP_SECRET."&code=".$code; 
    $access_token = file_get_contents($token_url); 

    $param1=explode("&",$access_token); 
    $param2=explode("=",$param1[0]); 
    $FB_ACCESS_TOKEN=$param2[1]; 


    $url = "https://graph.facebook.com/me/feed"; 
    $attachment = array( 'access_token' => $FB_ACCESS_TOKEN,       
        'name'   => $postName, 
        'link'   => $postLink, 
        'description' => $postDescription, 
        'message'  => $postMessage, 
        'caption'  => $postCaption, 
       ); 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,2); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment); 
    $result=curl_exec($ch); 
    header('Content-type:text/html'); 
    curl_close($ch); 

    return $result 
    } 







    ?> 

詳情 遵循How to post wall in facebook using API in PHP?

+0

非常感謝AKHIL 但我不能使用PHP我怕我的服務器上,是有什麼simular jQuery中 - JavaScript的? 我在上面的代碼中看到了dialog_url,上面的貼子是在我的牆上,所以它看起來就像我從Facebook內部發布它? 所以我可以發佈大圖片等? 我不希望它發佈評論,不喜歡這個例子:http://demo.lookmywebpage.com/publish-on-facebook-wall/ 我只想確保在我開始之前:-) 謝謝再次! – 2012-02-22 19:10:36

+0

只需嘗試一個演示與此,發佈到你的fb牆的東西,我希望一個嘗試將清除所有你的疑惑 – 2012-02-23 04:54:36

+0

好的謝謝你的幫助,但這是PHP代碼,不是嗎?而我的服務器不支持PHP。 而我不知道我是否理解它,如果我想從我的數據庫中獲取postmessage和其他值,我在哪裏放置它?我也想同時發送圖片,我該怎麼做? 對不起:-) – 2012-02-23 07:20:10

0

功能postonwall(){ // showLoader(true);

  FB.api('/me/feed', 'post', 
       { 
        message  : "testtext.", 
        link  : 'http://www.mydomain.se', 
        picture  : 'http://www.mydomain.se/image.jpg', 
        name  : 'iOS Apps & Games', 
        description : 'Checkout iOS apps and games from iThinkdiff.net. I found some of them are just awesome!' 

      }, 
      function(response) { 
       // showLoader(false); 

       if (!response || response.error) { 
        alert('Error occured'); 
       } else { 
        //alert('Post ID: ' + response.id); 
        alert('Success: Content Published'); 
       } 
      }); 
     } 
相關問題