douruhu4282 2016-08-18 06:30
浏览 43

我的facebook帖子应该自动发布在wordpress作为文章

i need your help. Actually i create a new page with wordpress and have a little problem. This new page is for a restaurant/bar.

We often post in Facebook our daily menu or specials. These post should be automatically insert into wordpress as articles. I found some plugins, they work, but the output are one long list of the post and not as articles.

First Plugin

Second Plugin

Anybody here, to knows a solution?

  • 写回答

1条回答 默认 最新

  • douzhang7184 2016-08-18 11:56
    关注

    There is a great tutorial on how to interact with the Graph API here: http://johndoesdesign.com/blog/2011/php/adding-a-facebook-news-status-feed-to-a-website/

    My personal approach is to wrap that code in a function and then echo that function in a theme´s template-file.

    Recipe:
    1. get an access token for the page
    2. create a function in your theme´s functions.php:

        function display_facebook_info() {
          $page_id = 'YOUR_PAGE_ID';
          $access_token = 'YOUR_ACCESS_TOKEN';
          //Get the JSON
          $json_object = @file_get_contents('https://graph.facebook.com/' . $page_id . 
          '/posts?access_token=' . $access_token);
          //Interpret data
          $fbdata = json_decode($json_object);
    
          foreach ($fbdata->data as $post )
            {
              $posts .= '<p><a href="' . $post->link . '">' . $post->story . '</a></p>';
              $posts .= '<p><a href="' . $post->link . '">' . $post->message . '</a></p>';
              $posts .= '<p>' . $post->description . '</p>';
              $posts .= '<br />';
          }
          //Display the posts
          echo $posts;
        }
    

    3. Display the posts in your template-file:

    <?php echo display_facebook_info(); ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000