我有一些网站带有自定义Facebook提要,可使用Graph API加载。
过去,所有内容加载都非常快,但是大约一两个星期以来,所有站点都停止在Feed部分加载,并且仅在30秒或更长时间后才完全加载。
这可能是什么原因?
我确定它是Facebook feed,因为当我将其删除时,该网站会再次快速加载。
以下是一个有此问题的网站的示例供稿:
$json_object = file_get_contents("https://graph.facebook.com/v3.2/thepagesid/posts?fields=full_picture%2Cmessage%2Cstory%2Cpermalink_url%2Cupdated_time%2Cfrom&access_token=mytoken");
$feedarray = json_decode($json_object);
$f = 0;
foreach ( $feedarray->data as $key => $feed_data )
{
if($feed_data->full_picture != ''){
$fbimage = $feed_data->full_picture;
}else{
$fbimage = 'assets/images/fbnoimg.jpg';
}
$shortstrfb = substr($feed_data->message, 0, 170) . '...';
if($feed_data->message != ''){
$f++;
}
if($f > 4){
break;
}
if($feed_data->message != '' && $feed_data->from->name == 'facebook page name'){
$facebookfeed .= '
<div class="col-lg-3 col-md-4 col-sm-6">
<div class="single-product-wrap fbwrapdiv">
<div class="product-image">
<a href="'.$feed_data->permalink_url.'" target="_blank">
<span class="datefb">'.date("d-m-Y",strtotime($feed_data->updated_time)).'</span>
<img class="fbimgclass" src="'.$fbimage.'" alt=""></a>
<div class="product-action">
<a href="'.$feed_data->permalink_url.'" target="_blank" class="wishlist"><i class="fab fa-facebook-f"></i></a>
</div>
</div>
<div class="product-content">
<div class="price-box">
<p class="facebooktext">'.$shortstrfb.'</p>
</div>
</div>
</div>
</div>';
}
}
echo $facebookfeed;
答案 0 :(得分:0)
我使用curl固定了它。
我替换了:
$json_object = file_get_contents("https://graph.facebook.com/v3.2/thepagesid/posts?fields=full_picture%2Cmessage%2Cstory%2Cpermalink_url%2Cupdated_time%2Cfrom&access_token=mytoken");
$feedarray = json_decode($json_object);
使用:
$graph_url = 'https://graph.facebook.com/v3.2/thepagesid/posts?fields=full_picture%2Cmessage%2Cstory%2Cpermalink_url%2Cupdated_time%2Cfrom&access_token=mytoken';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $graph_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($ch);
curl_close($ch);
$feedarray = json_decode($output);