ds34222 2014-04-26 09:07
浏览 61
已采纳

使用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.

  • 写回答

1条回答 默认 最新

  • douxun1407 2014-04-26 10:15
    关注

    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;
      }
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?