當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TwitterAPIExchange::get_tweets方法代碼示例

本文整理匯總了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;
}
開發者ID:sekane81,項目名稱:ratoninquietoweb,代碼行數:33,代碼來源:functions.php


注:本文中的TwitterAPIExchange::get_tweets方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。