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

报告相同问题?

悬赏问题

  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据