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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?