本文整理匯總了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;
}