【发布时间】:2016-09-25 11:21:18
【问题描述】:
我正在尝试在我的网站上显示一个 facebook 提要,它正在运行。但我只设法显示帖子的文本,而不是附加的图像(或者如果可能,如果有多个图像,只显示第一个或最大的一个)。
我尝试在 here 中查找正确的名称以使用 API 获取它
这是我现在的代码(在 owl carousel 中显示 Facebook 帖子):
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 会起作用,但它什么也没返回。
【问题讨论】:
标签: php facebook facebook-graph-api