本文整理汇总了PHP中TwitterAPIExchange::getLastStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP TwitterAPIExchange::getLastStatusCode方法的具体用法?PHP TwitterAPIExchange::getLastStatusCode怎么用?PHP TwitterAPIExchange::getLastStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwitterAPIExchange
的用法示例。
在下文中一共展示了TwitterAPIExchange::getLastStatusCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: requestTweets
public function requestTweets($append = false)
{
$this->getRateLimitStatus();
$maxId = isset($_GET['maxTweetId']) ? $_GET['maxTweetId'] : -1;
if (!isset($this->_tweets) || $append) {
$username = $this->_username;
$cache = Yii::app()->cache2;
$cacheKey = $this->getCacheKey();
$pageSize = 5;
$tweets = $cache->get($cacheKey);
if ($append && !$tweets) {
// another page of tweets has been requested but the newer tweets have been
// invalidated. To avoid having to determine how many pages down the user is,
// we simply refresh the feed.
$append = false;
$maxId = -1;
}
if (!$tweets || $append) {
// fetch tweets and add to cache
$tweetCount = 100;
$credentials = $this->getTwitterCredentials();
$resourceName = '/statuses/user_timeline.json';
$remainingRequests = $this->remainingRequests($resourceName);
if ($remainingRequests < 1) {
// rate limit met
throw new TwitterFeedWidgetException(Yii::t('app', 'Twitter feed could not be retrieved. Please try again later.'));
}
$url = 'https://api.twitter.com/1.1' . $resourceName;
$getfield = '?screen_name=' . $username . '&count=' . $tweetCount;
if ($append) {
$maxId = $tweets[count($tweets) - 1]['id_str'];
$getfield .= '&max_id=' . $maxId;
}
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($credentials);
$oldTweets = $tweets;
$tweets = CJSON::decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest());
if (($statusCode = $twitter->getLastStatusCode()) != 200) {
$this->throwApiException($tweets, $statusCode);
}
$this->remainingRequests($resourceName, $remainingRequests - 1);
if ($append) {
$tweets = array_merge($oldTweets, $tweets);
}
$cache->set($cacheKey, $tweets, 60 * 5);
//AuxLib::debugLogR ('cache miss');
} else {
//AuxLib::debugLogR ('cache hit');
}
if ($maxId === -1) {
// initial page load, just return the first page
$this->_tweets = array_slice($tweets, 0, $pageSize);
} else {
// max id specified, return all tweets up one page beyond max id
$tweetCount = count($tweets);
$found = false;
for ($i = 0; $i < $tweetCount; $i++) {
$tweet = $tweets[$i];
if ($tweet['id_str'] == $maxId) {
$found = true;
break;
}
}
if ($found && $i + $pageSize < $tweetCount) {
$this->_tweets = array_slice($tweets, 0, $i + $pageSize + 1);
} else {
if (!$append) {
// only request more tweets once
return $this->requestTweets(true);
} else {
// giving up on searching for specified tweet, just display the first page
$this->_tweets = array_slice($tweets, 0, $pageSize);
}
}
}
}
return $this->_tweets;
}