我写过这个函数:
public function returnAllFeeds($responseType = RESPONSE_RETURN)
{
$twitter = $this->getTwitterFeeds();
$instagram = $this->getInstagramFeeds();
$facebook = $this->getFacebookResponse();
$allFeeds = $this->sortNjoin($twitter,$instagram, $facebook);
if($responseType == RESPONSE_JSON)
{
echo json_encode($allFeeds);
}
else
{
return $allFeeds;
}
}
来自twitter,facebook和Instagram的所有提要都被提取,但每次php获取数据至少需要5-6秒,所以我想知道它们是否是一种减少卷曲获取时间的方法。
这里有更多代码:
public function getFacebookResponse($responseType = RESPONSE_RETURN)
{
$params = array(
'access_token' => FACEBOOK_TOKEN,
'limit' => '30',
'fields' => 'message,permalink_url,id,from,name,picture,source,updated_time'
);
$fbFeeds[] = $this->curl_library->getFacebookPosts('godoolallyandheri',$params);
$fbFeeds[] = $this->curl_library->getFacebookPosts('godoolallybandra',$params);
$fbFeeds[] = $this->curl_library->getFacebookPosts('godoolally',$params);
if($responseType == RESPONSE_JSON)
{
echo json_encode($fbFeeds);
}
else
{
return array_merge($fbFeeds[0]['data'],$fbFeeds[1]['data'],$fbFeeds[2]['data']);
}
}
public function getTwitterFeeds($responseType = RESPONSE_RETURN)
{
$twitterFeeds = '';
$this->twitter->tmhOAuth->reconfigure();
$parmas = array(
'count' => '61',
'exclude_replies' => 'true',
'screen_name' => 'godoolally'
);
$responseCode = $this->twitter->tmhOAuth->request('GET','https://api.twitter.com/1.1/statuses/user_timeline.json',$parmas);
if($responseCode == 200)
{
$twitterFeeds = $this->twitter->tmhOAuth->response['response'];
}
$twitterFeeds = json_decode($twitterFeeds,true);
if($responseType == RESPONSE_JSON)
{
echo json_encode($twitterFeeds);
}
else
{
return $twitterFeeds;
}
}
public function getInstagramFeeds($responseType = RESPONSE_RETURN)
{
$instaFeeds = $this->curl_library->getInstagramPosts();
if(!myIsMultiArray($instaFeeds))
{
$instaFeeds = null;
}
else
{
$instaFeeds = $instaFeeds['posts']['items'];
}
if($responseType == RESPONSE_JSON)
{
echo json_encode($instaFeeds);
}
else
{
return $instaFeeds;
}
}
并不真正关心sortNJoin只需要ms来执行