使用FB-API和PHP在Facebook粉丝页面上发布链接和图像

问题描述:

Hey guys all the answeres i read where realy old and i think facebook updated a lot! Is somebody up to date with this problem? Knows a good tutorial or have some tips?

Kind Regards, Freddy

EDIT:

I do have a website where are news posted and i want to share them automatically on my facebook fan page. This post should contain an image and the link to my page.

嘿伙计们我读到的所有回答真的很老了,我认为facebook更新了很多! 有人是最新的 有这个问题? 知道一个很好的教程或有一些提示吗? p>

亲切的问候, Freddy p>

编辑: p>

我 有一个新闻发布的网站,我想在我的脸书粉丝页面上自动分享。 这篇文章应该包含一个图像和我页面的链接。 p> div>

I think the best approach to do this-

  1. First get the page access token of your page, then extend it to never expiring. (Permission required to get the page access token: manage_pages). See here how to get the never expiring page access token.

  2. Then simply use this token to post on the fanpage's wall as a page itself! I'm not sure if you are using any SDK (you have not mentioned in the ques), but if you dont want to use anyy SDK you can simply use curl to post on the wall-

    $url = "https://graph.facebook.com/{page-id}/feed";
    $attachment =  array(
            'access_token'  => $page_access_token,  // never-expiring token
            'message' => '{message}',
            'picture' => '{picture}',
            'link' => '{link}'
    );
    
    print_r(json_encode($attachment));
    $result = GetContentsUsingCurl($url, $attachment);
    $result = json_decode($result, TRUE);
    echo "<pre>";
    print_r($result);
    
    function GetContentsUsingCurl($url, $attachment){
       $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_POST, true);
       curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
       curl_setopt($ch, CURLOPT_HEADER, 0);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       $result = curl_exec($ch);
       curl_close ($ch);
    
       return $result;
    }