Php 从公共页面上的facebook帖子获取图像
我正在尝试在我的网站上显示一个facebook提要,它正在运行。但是我只显示了帖子的文本,而没有显示贴在帖子上的图片(如果可能的话,如果有多张图片,只显示第一张或最大的一张) 我尝试使用API查找正确的名称来获取它 这是我现在的代码(显示猫头鹰转盘中的facebook帖子):Php 从公共页面上的facebook帖子获取图像,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,我正在尝试在我的网站上显示一个facebook提要,它正在运行。但是我只显示了帖子的文本,而没有显示贴在帖子上的图片(如果可能的话,如果有多张图片,只显示第一张或最大的一张) 我尝试使用API查找正确的名称来获取它 这是我现在的代码(显示猫头鹰转盘中的facebook帖子): 函数fetchUrl($url){ $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$URL); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1)
函数fetchUrl($url){
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_超时,20);
//您可能需要在下面添加一行
//curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
$feedData=curl\u exec($ch);
卷曲关闭($ch);
返回$feedData;
}
//应用程序信息,需要进行身份验证
$app_id=“1230330267012270”;
$app_secret=“secret”;
//检索身份验证令牌
$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\U解码($json\U对象);
foreach($feedarray->data as$feed\u data)
{
如果($feed_data->message!=''){
$facebookfeed.='
“.$feed_data->name”
。$feed\u data->message
“.$feed_data->story”
图片。“”>
';
}
}
echo$facebookfeed;
查看Facebook文档时,我认为$feed\u data->picture
可以工作,但它没有返回任何内容
为了尝试提高移动网络上的性能,v2.4中的节点和边缘要求您明确请求GET请求所需的字段。例如,默认情况下,GET/v2.4/me/feed不再包括喜欢和评论,但GET/v2.4/me/feed?fields=评论,喜欢将返回数据
来源:最后一个问题:我可以从一个curl获取所有数据吗?还是需要两个?我尝试了以下方法:
$json\u object=fetchUrl(“https://graph.facebook.com/267007566742236/feed?fields=full_picture&{$authToken}”);
但这会阻止返回任何数据。
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;