从公开页面上的Facebook帖子获取图像 [英] Getting an image from a facebook post on a public page

查看:77
本文介绍了从公开页面上的Facebook帖子获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网站上显示一个Facebook供稿,该网站正在运行.但是我只设法显示帖子的文本,而不显示附件的图像(或者,如果可能的话,如果有多个图像,则仅显示第一个或最大的图像).

I'm trying to show a facebook feed on my website, which is working. But I only managed to show the text of the post, not the image attached to it (or if possible, if there are multiple images, only the first one or biggest one).

我尝试在此处查找正确的名称使用API​​来获取它

I tried looking here for the correct name to get it using the API

这是我的代码(在猫头鹰轮播中显示Facebook帖子):

This is my code now (which shows facebook posts in an owl carousel):

function fetchUrl($url){    
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 20);
     // You may need to add the line below
     // curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);

     $feedData = curl_exec($ch);
     curl_close($ch); 

     return $feedData;

    }

    //App Info, needed for Auth
    $app_id = "1230330267012270";
    $app_secret = "secret";

    //Retrieve auth token
    $authToken = fetchUrl("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=1230330267012270&client_secret=secret");

    $json_object = fetchUrl("https://graph.facebook.com/267007566742236/feed?{$authToken}");

    $feedarray = json_decode($json_object);


    foreach ( $feedarray->data as $feed_data )
    {

        if($feed_data->message != ''){
            $facebookfeed .= '
                <div class="item">
                      <div class="product-item">
                            <img class="img-responsive" src="images/siteimages/imgfacebook.jpg" alt="">
                            <h4 class="product-title">'.$feed_data->name.'</h4>
                            <p class="product-desc">'.$feed_data->message.'</p>
                            <p>'.$feed_data->story.'</p>
                            <img src="'.$feed_data->picture.'">
                            <p><a href="#" class="btn btn-primary">Lees meer</a></p>
                        </div><!-- Product item end -->
                </div><!-- Item 1 end -->';
        }
    }
echo $facebookfeed;

看看Facebook文档,我以为$feed_data->picture可以用,但是什么也没返回.

Looking at the Facebook documentation I thought $feed_data->picture would work, but it returns nothing.

推荐答案

要尝试提高移动网络的性能,v2.4中的节点和边缘"要求您显式请求GET请求所需的字段.例如,默认情况下,GET/v2.4/me/feed不再包含喜欢和评论,但是GET/v2.4/me/feed?fields=comments,喜欢将返回数据.

To try to improve performance on mobile networks, Nodes and Edges in v2.4 requires that you explicitly request the field(s) you need for your GET requests. For example, GET /v2.4/me/feed no longer includes likes and comments by default, but GET /v2.4/me/feed?fields=comments,likes will return the data.

来源: https://developers.facebook.com/docs/apps/changelog# v2_4

这篇关于从公开页面上的Facebook帖子获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆