本文整理汇总了PHP中TwitterAPIExchange::get_tweets方法的典型用法代码示例。如果您正苦于以下问题:PHP TwitterAPIExchange::get_tweets方法的具体用法?PHP TwitterAPIExchange::get_tweets怎么用?PHP TwitterAPIExchange::get_tweets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwitterAPIExchange
的用法示例。
在下文中一共展示了TwitterAPIExchange::get_tweets方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boston_return_tweets
function boston_return_tweets($count = 1)
{
include_once locate_template('includes/twitter_api.php');
$username = boston_get_option('twitter-username');
$oauth_access_token = boston_get_option('twitter-oauth_access_token');
$oauth_access_token_secret = boston_get_option('twitter-oauth_access_token_secret');
$consumer_key = boston_get_option('twitter-consumer_key');
$consumer_secret = boston_get_option('twitter-consumer_secret');
if (!empty($username) && !empty($oauth_access_token) && !empty($oauth_access_token_secret) && !empty($consumer_key) && !empty($consumer_secret)) {
$cache_file = dirname(__FILE__) . '/includes/' . 'twitter-cache.txt';
if (!file_exists($cache_file)) {
file_put_contents($cache_file, '');
}
$modified = filemtime($cache_file);
$now = time();
$interval = 600;
// ten minutes
$response = json_decode(file_get_contents($cache_file), true);
if (!$modified || empty($response) || $now - $modified > $interval || !empty($response['errors']) || !empty($response['error'])) {
$settings = array('oauth_access_token' => $oauth_access_token, 'oauth_access_token_secret' => $oauth_access_token_secret, 'consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret, 'username' => $username, 'tweets' => $count);
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->get_tweets();
if ($response) {
$cache_static = fopen($cache_file, 'w');
fwrite($cache_static, json_encode($response));
fclose($cache_static);
}
}
} else {
$response = array('error' => 'NOK');
}
return $response;
}