• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP getConnectionWithAccessToken函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中getConnectionWithAccessToken函数的典型用法代码示例。如果您正苦于以下问题:PHP getConnectionWithAccessToken函数的具体用法?PHP getConnectionWithAccessToken怎么用?PHP getConnectionWithAccessToken使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了getConnectionWithAccessToken函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct($arr)
 {
     $this->services = $arr;
     if (trim($arr['twitterName'])) {
         $connection = getConnectionWithAccessToken($arr['consumer_key'], $arr['consumer_secret'], $arr['access_token'], $arr['access_token_secret']);
         $tweets = $connection->get('https://api.twitter.com/1.1/users/show.json?screen_name=' . $arr['twitterName']) or die('Couldn\'t retrieve tweets! Wrong username?');
         if (!empty($tweets->errors)) {
             if ($tweets->errors[0]->message == 'Invalid or expired token') {
                 echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget;
             } else {
                 echo '<strong>' . $tweets->errors[0]->message . '</strong>' . $after_widget;
             }
             return;
         }
         $new_twitter = $tweets->followers_count;
         if (empty($new_twitter) || $new_twitter == 0 || $new_twitter == '0') {
             $this->twitter = $arr['twitter'];
         } else {
             $this->twitter = $new_twitter;
         }
     }
     if (trim($arr['facebookFanPageURL'])) {
         $query = wp_remote_get('https://api.facebook.com/method/links.getStats?urls=' . urlencode(trim($arr['facebookFanPageURL'])) . '&format=json');
         if (is_wp_error($query)) {
             print_r($query);
         }
         $result = json_decode($query['body'], true);
         if (empty($result[0]['like_count']) || $result[0]['like_count'] == 0 || $result[0]['like_count'] == '0') {
             $this->facebook = $arr['facebook'];
         } else {
             $this->facebook = $result[0]['like_count'];
         }
     }
 }
开发者ID:VipinMundayad,项目名称:ChinUpd8,代码行数:34,代码来源:scw_stats.class.php


示例2: etheme_capture_tweets

function etheme_capture_tweets($consumer_key, $consumer_secret, $user_token, $user_secret, $user, $count)
{
    $connection = getConnectionWithAccessToken($consumer_key, $consumer_secret, $user_token, $user_secret);
    $params = array('screen_name' => $user, 'count' => $count);
    $content = $connection->get("statuses/user_timeline", $params);
    //prar($content);
    return json_encode($content);
}
开发者ID:phanhoanglong2610,项目名称:flowershop,代码行数:8,代码来源:twitter.php


示例3: widget

 function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     $twitter_username = $instance['twitter_username'];
     $show_num = $instance['show_num'];
     $consumer_key = $instance['consumer_key'];
     $consumer_secret = $instance['consumer_secret'];
     $access_token = $instance['access_token'];
     $access_token_secret = $instance['access_token_secret'];
     $cache_time = $instance['cache_time'];
     // Opening of widget
     echo $before_widget;
     // Open of title tag
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     $last_cache_time = get_option('gdl_twitter_widget_last_cache_time', 0);
     $diff = time() - $last_cache_time;
     $crt = $cache_time * 3600;
     if (empty($last_cache_time) || $diff >= $crt) {
         $connection = getConnectionWithAccessToken($consumer_key, $consumer_secret, $access_token, $access_token_secret);
         $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitter_username . "&count=" . $show_num) or die('Couldn\'t retrieve tweets! Wrong username?');
         if (!empty($tweets->errors)) {
             if ($tweets->errors[0]->message == 'Invalid or expired token') {
                 echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget;
             } else {
                 echo '<strong>' . $tweets->errors[0]->message . '</strong>' . $after_widget;
             }
             return;
         }
         $tweets_data = array();
         for ($i = 0; $i <= count($tweets); $i++) {
             if (!empty($tweets[$i])) {
                 $tweets_data[$i]['created_at'] = $tweets[$i]->created_at;
                 $tweets_data[$i]['text'] = $tweets[$i]->text;
                 $tweets_data[$i]['status_id'] = $tweets[$i]->id_str;
             }
         }
         update_option('gdl_twitter_widget_tweets', serialize($tweets_data));
         update_option('gdl_twitter_widget_last_cache_time', time());
     } else {
         $tweets_data = maybe_unserialize(get_option('gdl_twitter_widget_tweets'));
     }
     echo '<div class="twitter-whole">';
     echo '<ul id="twitter_update_list">';
     foreach ($tweets_data as $each_tweet) {
         echo '<li>';
         echo '<span>' . convert_links($each_tweet['text']) . '</span>';
         echo '<a target="_blank" href="http://twitter.com/' . $twitter_username . '/statuses/' . $each_tweet['status_id'] . '">' . relative_time($each_tweet['created_at']) . '</a>';
         echo '</li>';
     }
     echo '</ul>';
     echo '</div>';
     // Closing of widget
     echo $after_widget;
 }
开发者ID:shimion,项目名称:preview1,代码行数:57,代码来源:twitter-widget.php


示例4: tweet

function tweet($update)
{
    global $config;
    $connection = getConnectionWithAccessToken($config['twitter_oauth_token'], $config['twitter_oauth_token_secret']);
    $parameters = array('status' => $update);
    $status = $connection->post('statuses/update', $parameters);
    // Don't uncomment this as it will break "Update" button in OpenURL results
    //print_r($status);
}
开发者ID:rdmpage,项目名称:bioguid,代码行数:9,代码来源:twitter.php


示例5: get

 function get($count = 20)
 {
     $username = $this->username;
     // Append the count
     $url = $this->feedUrl;
     $url .= '&count=' . $count;
     $tweets_cache_path = get_template_directory() . '/cache/twitter_' . $username . '_' . $count . '.cache';
     if (file_exists($tweets_cache_path)) {
         $tweets_cache_timer = intval((time() - filemtime($tweets_cache_path)) / 60);
     } else {
         $tweets_cache_timer = 0;
     }
     if (!file_exists($tweets_cache_path) or $tweets_cache_timer > 15) {
         $connection = getConnectionWithAccessToken($this->consumer_key, $this->consumer_secret, $this->access_token, $this->access_token_secret);
         $tweets = $connection->get($url);
         if (!empty($tweets->errors)) {
             if ($tweets->errors[0]->message == 'Invalid or expired token') {
                 echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget;
             } else {
                 echo '<strong>' . $tweets->errors[0]->message . '</strong>' . $after_widget;
             }
             return;
         }
         $tweets_data = array();
         foreach ($tweets as $tweet) {
             $tweets_data[]['text'] = $tweet->text;
         }
         if (file_exists($tweets_cache_path)) {
             unlink($tweets_cache_path);
         }
         $myFile = $tweets_cache_path;
         $fh = fopen($myFile, 'w') or die("can't open file");
         $stringData = serialize($tweets_data);
         fwrite($fh, $stringData);
         fclose($fh);
         //clear data
         $tweets_data = array();
     }
     error_reporting(0);
     $file = file_get_contents($tweets_cache_path, true);
     if (!empty($file)) {
         $tweets = unserialize($file);
         // Some reformatting
         $pattern = array('/[^(:\\/\\/)](www\\.[^ \\n\\r]+)/', '/(https?:\\/\\/[^ \\n\\r]+)/');
         $replace = array('<a href="http://$1" rel="nofollow">$1</a>', '<a href="$1" rel="nofollow">$1</a>');
         foreach ($tweets as $tweet) {
             $formatted_tweet = preg_replace($pattern, $replace, $tweet['text']);
             $formatted_tweet = auto_link_twitter($formatted_tweet);
             $tweets_data[]['text'] = $formatted_tweet;
         }
     }
     return $tweets_data;
 }
开发者ID:shrtbbbl,项目名称:happyhoppy,代码行数:53,代码来源:twitter.lib.php


示例6: __construct

 public function __construct($lng, $lat)
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . "/twitteroauth-master/connect.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/twitteroauth-master/twitteroauth/twitteroauth.php";
     function getConnectionWithAccessToken($oauth_token, $oauth_token_secret)
     {
         $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);
         return $connection;
     }
     $connection = getConnectionWithAccessToken("53207076-VqragtGcaPWoldCNrfbnwwWG4dUnP0BbeKcW4xt8m", "OdeBMzodirvxoDrgkKJxNvkEBeB87TUCkamvMpqyULsgq");
     $content = $connection->get("https://api.twitter.com/1.1/geo/search.json?accuracy=3000&lat=38.6480&long=-90.3050");
     $place_id = $content->result->places[0]->id;
     $base_url = "https://twitter.com/search?q=place%3A" . $place_id;
     echo $base_url;
 }
开发者ID:Brian-Lam,项目名称:College-Personality-Profiler,代码行数:15,代码来源:Twitter.php


示例7: getTweets

function getTweets($twitteruser)
{
    $notweets = 6;
    $consumerkey = "91VWoS0052BKjczqL9LMNKumm";
    $consumersecret = "YPrff3DTDtUw0i3iSRlGQGaGEEG2kW6CqwBFA5PV0Hfs62NDY7";
    $accesstoken = "27766009-jWBg4UotrwxP4f3WWYuwHFlwZeg6fJrrKmXOu52CF";
    $accesstokensecret = "1bAeS1A2wBzkqkPbQZOxViqDb2sOPblPe9IugMz9YsMnI";
    function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret)
    {
        $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
        return $connection;
    }
    $connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
    $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitteruser . "&count=" . $notweets);
    return $tweets;
}
开发者ID:JonathanCosta,项目名称:Vou-de-Marisa,代码行数:16,代码来源:tweets.php


示例8: get

 function get($count = 20)
 {
     $username = $this->username;
     // Append the count
     $url = $this->feedUrl;
     $url .= '&count=' . $count;
     $tweets_cache_path = THEMEUPLOAD . '/twitter_' . $username . '_' . $count . '.cache';
     if (file_exists($tweets_cache_path)) {
         $tweets_cache_timer = intval((time() - filemtime($tweets_cache_path)) / 60);
     } else {
         $tweets_cache_timer = 0;
     }
     if (!file_exists($tweets_cache_path) or $tweets_cache_timer > 15) {
         $connection = getConnectionWithAccessToken($this->consumer_key, $this->consumer_secret, $this->access_token, $this->access_token_secret);
         $tweets = $connection->get($url);
         if (!empty($tweets->errors)) {
             if ($tweets->errors[0]->message == 'Invalid or expired token') {
                 echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!';
             } else {
                 echo '<strong>' . $tweets->errors[0]->message . '</strong>';
             }
             return;
         }
         $tweets_data = array();
         foreach ($tweets as $tweet) {
             $tweet_text = auto_link_twitter($tweet->text);
             $tweets_data[]['text'] = $tweet_text;
         }
         if (file_exists($tweets_cache_path)) {
             unlink($tweets_cache_path);
         }
         $myFile = $tweets_cache_path;
         $fh = fopen($myFile, 'w') or die("can't open file");
         $stringData = serialize($tweets_data);
         fwrite($fh, $stringData);
         fclose($fh);
     } else {
         $file = file_get_contents($tweets_cache_path, true);
         if (!empty($file)) {
             $tweets = unserialize($file);
             foreach ($tweets as $tweet) {
                 $tweets_data[]['text'] = $tweet['text'];
             }
         }
     }
     return $tweets_data;
 }
开发者ID:rsantellan,项目名称:wordpress-ecommerce,代码行数:47,代码来源:twitter.lib.php


示例9: twitter_parse_cache_feed

function twitter_parse_cache_feed($args = '')
{
    /* Set up the default arguments for the twitter. */
    $defaults = array('username' => '', 'limit' => '', 'encode_utf8' => 'false', 'twitter_cons_key' => '', 'twitter_cons_secret' => '', 'twitter_oauth_token' => '', 'twitter_oauth_secret' => '');
    $args = apply_filters('twitter_parse_cache_feed_args', $args);
    $args = wp_parse_args($args, $defaults);
    $out = '';
    global $twitter_options;
    if (!(require_once FRAMEWORK_DIR . 'includes/twitteroauth.php')) {
        $out .= '<strong>Couldn\'t find twitteroauth.php!</strong>';
        return;
    }
    $connection = getConnectionWithAccessToken($args['twitter_cons_key'], $args['twitter_cons_secret'], $args['twitter_oauth_token'], $args['twitter_oauth_secret']);
    $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $args['username'] . "&count=" . $args['limit'] . "") or die('Couldn\'t retrieve tweets! Wrong username?');
    //print_r($tweets);
    if (!empty($tweets->errors)) {
        if ($tweets->errors[0]->message == 'Invalid or expired token') {
            $out .= '<strong>' . $tweets->errors[0]->message . '!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget;
        } else {
            $out .= '<strong>' . $tweets->errors[0]->message . '</strong>';
        }
        return;
    }
    $out .= '<ul class="tweet">';
    for ($i = 0; $i <= count($tweets); $i++) {
        if (!empty($tweets[$i])) {
            $out .= '<li><i class="icon-twitter"></i>';
            $msg = " " . $tweets[$i]->text . " ";
            if ($args['encode_utf8']) {
                $msg = utf8_encode($msg);
            }
            //$link = $message->get_link();
            $time = $tweets[$i]->created_at;
            $msg = hyperlinks($msg);
            $msg = twitter_users($msg);
            $out .= $msg;
            $out .= '<span> - ' . relativeTime($time) . '</span>';
            $out .= '</li>';
        }
    }
    $out .= '</ul>';
    echo $out;
}
开发者ID:pryspry,项目名称:MusicPlay,代码行数:43,代码来源:class_twitter.php


示例10: get_recent_tweet_by_username

function get_recent_tweet_by_username($username = null)
{
    if ($username) {
        $twitteruser = $username;
        $number = 1;
        $consumerkey = get_field('sdo_api_twitter_app_consumer_key', 'options');
        $consumersecret = get_field('sdo_api_twitter_app_consumer_secret', 'options');
        $accesstoken = get_field('sdo_api_twitter_app_access_token', 'options');
        $accesstokensecret = get_field('sdo_api_twitter_app_access_token_secret', 'options');
        function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret)
        {
            $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
            return $connection;
        }
        $connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
        $tweet = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitteruser . "&count=" . $number . "&exclude_replies=true&include_rts=false&contributor_details=true&include_entities=true");
        return $tweet[0];
    }
}
开发者ID:aiganebraska,项目名称:AIGA-Nebraska,代码行数:19,代码来源:api_twitter.php


示例11: get_tweets

function get_tweets()
{
    // The $_REQUEST contains all the data sent via ajax
    if (isset($_REQUEST)) {
        /*// get Vancouver weather from Environment Canada
                $xml=simplexml_load_file("https://weather.gc.ca/rss/city/bc-74_e.xml") or $xml = null;
        
                $weather = "";
                if ($xml) {
                    $weather = $xml->entry[1]->title;
                    $weather = substr($weather, 20); // removes "Current Conditions: " from beginning.
        
        
                    $date = $xml->entry[1]->updated;
                    $date = new DateTime($date);
                    $date = $date->format('d/m/y');
                    $weather = $date." | ".$weather;
                }
        
                echo ($weather);*/
        require_once "twitteroauth-master/twitteroauth/twitteroauth.php";
        //Path to twitteroauth library
        $twitteruser = "fieldhockeycan";
        $notweets = 2;
        $consumerkey = "PlxuNdfmNQg1rt9pnF0L8K1kU";
        $consumersecret = "Wkulo79SOsEmlQvqmSCDaiDbO8ywRa0JIvvoBMFdaYPL2d5gH6";
        $accesstoken = "14864996-Ya9fNZarCjMYNyK6HPluj0Mothx3LpioeOdJYCEM5";
        $accesstokensecret = "lqGV9eWg3X6mEWDSnuz4no83cGMXtIZYV6QSNd2jprC0f";
        function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret)
        {
            $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
            return $connection;
        }
        $connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
        $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitteruser . "&count=" . $notweets);
        echo json_encode($tweets);
    }
    // Always die in functions echoing ajax content
    die;
}
开发者ID:bigmikestudios,项目名称:bms_ajax_social,代码行数:40,代码来源:bms_ajax_social.php


示例12: twitter_get_tweets

function twitter_get_tweets($twitteruser)
{
    $cache = get_transient('revoke_twitter');
    if (is_array($cache) && array_key_exists($twitteruser, $cache)) {
        return $cache[$twitteruser];
    }
    $consumerkey = _go('twitter_consumerkey');
    $consumersecret = _go('twitter_consumersecret');
    $accesstoken = _go('twitter_accesstoken');
    $accesstokensecret = _go('twitter_accesstokensecret');
    if (empty($consumerkey) || empty($consumersecret) || empty($accesstoken) || empty($accesstokensecret)) {
        return null;
    }
    $connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
    $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitteruser);
    if (!is_array($cache)) {
        $cache = array();
    }
    $cache[$twitteruser] = $tweets;
    set_transient('revoke_twitter', $cache, 60);
    return $tweets;
}
开发者ID:sissisnothere,项目名称:testWeb,代码行数:22,代码来源:twitter.php


示例13: chronos_twitter_feed

function chronos_twitter_feed($count = '1', $list = false)
{
    global $user, $consumerkey, $consumersecret, $accesstoken, $accesstokensecret;
    $output = '';
    $i = 1;
    $twitteruser = $user;
    $notweets = $count;
    $connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
    $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitteruser . "&count=" . $notweets);
    $data = json_decode(json_encode($tweets));
    if (is_array($data)) {
        while ($i <= $count) {
            if (isset($data[$i - 1])) {
                $feed = $data[$i - 1]->text;
                $feed = str_pad($feed, 3, ' ', STR_PAD_LEFT);
                $startat = stripos($feed, '@');
                $numat = substr_count($feed, '@');
                $numhash = substr_count($feed, '#');
                $numhttp = substr_count($feed, 'http');
                $feed = preg_replace("#(^|[\n ])([\\w]+?://[\\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $feed);
                $feed = preg_replace("#(^|[\n ])((www|ftp)\\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $feed);
                $feed = preg_replace("/@(\\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $feed);
                $feed = preg_replace("/#(\\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $feed);
                if (!$list) {
                    $output .= sprintf('<div class="">%2$s</div><div class="">%1$s</div>', $feed, chronos_time_ago(strtotime($data[$i - 1]->created_at)));
                } else {
                    $output .= sprintf('<div class="single_row margin-bottom24"><i class="fa fa-twitter icon_element"></i><div class="text border-box">%1$s</div><div class="clearfix"></div></div><!-- single_row -->', $feed);
                }
                if ($i !== $count && $list) {
                    $output .= '<div class="small_separator background-color-passive margin-bottom24"></div>';
                }
            }
            $i++;
        }
        return $output;
    } else {
        return 'Twitter unaviable';
    }
}
开发者ID:da7id,项目名称:smileplumb,代码行数:39,代码来源:twitter.php


示例14: get_theme_tweets

 function get_theme_tweets($username, $consumerkey, $consumerkeysecret, $accesstoken, $accesstokensecret, $notweets)
 {
     //check settings and die if not set
     if (empty($username) || empty($consumerkey) || empty($consumerkeysecret) || empty($accesstoken) || empty($accesstokensecret)) {
         echo '<strong>Please fill all Twitter settings!</strong>';
         return;
     }
     //	yes, it needs update
     if (!(require_once 'twitter_oauth.php')) {
         echo '<strong>Couldn\'t find twitter_oauth.php!</strong>';
         return;
     }
     if (!function_exists('getConnectionWithAccessToken')) {
         function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret)
         {
             $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
             return $connection;
         }
     }
     $connection = getConnectionWithAccessToken($consumerkey, $consumerkeysecret, $accesstoken, $accesstokensecret);
     $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $username . "&count=5") or die('Couldn\'t retrieve tweets! Wrong username?');
     if (!empty($tweets->errors)) {
         if ($tweets->errors[0]->message == 'Invalid or expired token') {
             echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You will need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget;
         } else {
             echo '<strong>' . $tweets->errors[0]->message . '</strong>' . $after_widget;
         }
         return;
     }
     for ($i = 0; $i <= count($tweets); $i++) {
         if (!empty($tweets[$i])) {
             $tweets_array[$i]['created_at'] = $tweets[$i]->created_at;
             $tweets_array[$i]['text'] = $tweets[$i]->text;
             $tweets_array[$i]['status_id'] = $tweets[$i]->id_str;
         }
     }
     set_transient('twitter-bar-tweets', $tweets_array, 0);
     //convert links to clickable format
     function convert_links($status, $targetBlank = true, $linkMaxLen = 250)
     {
         // the target
         $target = $targetBlank ? " target=\"_blank\" " : "";
         // convert link to url
         $status = preg_replace("/((http:\\/\\/|https:\\/\\/)[^ )\n]+)/e", "'<a href=\"\$1\" title=\"\$1\" {$target} >'. ((strlen('\$1')>={$linkMaxLen} ? substr('\$1',0,{$linkMaxLen}).'...':'\$1')).'</a>'", $status);
         // convert @ to follow
         $status = preg_replace("/(@([_a-z0-9\\-]+))/i", "<a href=\"http://twitter.com/\$2\" title=\"Follow \$2\" {$target} >\$1</a>", $status);
         // convert # to search
         $status = preg_replace("/(#([_a-z0-9\\-]+))/i", "<a href=\"https://twitter.com/search?q=\$2\" title=\"Search \$1\" {$target} >\$1</a>", $status);
         // return the status
         return $status;
     }
     //convert dates to readable format
     function relative_time($a)
     {
         //get current timestampt
         $b = strtotime("now");
         //get timestamp when tweet created
         $c = strtotime($a);
         //get difference
         $d = $b - $c;
         //calculate different time values
         $minute = 60;
         $hour = $minute * 60;
         $day = $hour * 24;
         $week = $day * 7;
         if (is_numeric($d) && $d > 0) {
             //if less then 3 seconds
             if ($d < 3) {
                 return "right now";
             }
             //if less then minute
             if ($d < $minute) {
                 return floor($d) . " seconds ago";
             }
             //if less then 2 minutes
             if ($d < $minute * 2) {
                 return "about 1 minute ago";
             }
             //if less then hour
             if ($d < $hour) {
                 return floor($d / $minute) . " minutes ago";
             }
             //if less then 2 hours
             if ($d < $hour * 2) {
                 return "about 1 hour ago";
             }
             //if less then day
             if ($d < $day) {
                 return floor($d / $hour) . " hours ago";
             }
             //if more then day, but less then 2 days
             if ($d > $day && $d < $day * 2) {
                 return "yesterday";
             }
             //if less then year
             if ($d < $day * 365) {
                 return floor($d / $day) . " days ago";
             }
             //else return more than a year
             return "over a year ago";
//.........这里部分代码省略.........
开发者ID:primarydesign,项目名称:the-color-mint,代码行数:101,代码来源:twitter_gettweets.php


示例15: getConnectionWithAccessToken

</p>
                    </div>
                    <br class="visiblephone">
                    <div class="span9">
                        <div class="well" style=" box-shadow:none !important; margin-bottom:0px; background:#303030; border:0px; border-radius:0px !important">
								<?php 
    if (!(require_once 'inc/twitteroauth.php')) {
        echo '<strong>Couldn\'t find twitteroauth.php!</strong>';
        return;
    }
    function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret)
    {
        $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
        return $connection;
    }
    $connection = getConnectionWithAccessToken($b_data['TW_CONSUMER_KEY'], $b_data['TW_CONSUMER_SECRET'], $b_data['TW_OAUTH_TOKEN'], $b_data['TW_OAUTH_SECRET']);
    $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $b_data['TW_USERNAME'] . "&count=" . $b_data['TW_NUMBER']);
    if (!empty($tweets->errors)) {
        if ($tweets->errors[0]->message == 'Invalid or expired token') {
            echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!';
        } else {
            echo '<strong>' . $tweets->errors[0]->message . '</strong>';
        }
    }
    if (is_array($tweets)) {
        for ($i = 0; $i <= count($tweets); $i++) {
            if (!empty($tweets[$i])) {
                $tweets_array[$i]['created_at'] = $tweets[$i]->created_at;
                $tweets_array[$i]['text'] = $tweets[$i]->text;
                $tweets_array[$i]['status_id'] = $tweets[$i]->id_str;
            }
开发者ID:jw-psychopomp,项目名称:ThirtyNorth-wp-content,代码行数:31,代码来源:footer.php


示例16: display_latest_tweets

function display_latest_tweets($twitter_user_id, $cache_file = './tweets.txt', $tweets_to_display = 5, $ignore_replies = false, $include_rts = false, $twitter_wrap_open = '<ul class="slides">', $twitter_wrap_close = '</ul>', $tweet_wrap_open = '<li>', $meta_wrap_open = '<p class="tweet-meta">', $time_open = '<span class="tweet-time">', $time_close = '</span>', $meta_wrap_close = '</p><p class="tweet-text">', $tweet_wrap_close = '</p></li>', $date_format = 'g:i A M jS', $twitter_style_dates = true)
{
    // Twitter style days. [about an hour ago] (Default : true)
    // Twitter keys (You'll need to visit https://dev.twitter.com and register to get these.
    $consumerkey = "sNjEbKxd2hvm24OQKmsbNDHsd";
    $consumersecret = "zYdQ3az6X9EDjfqJREhCCw0mVLnSqzZamL5tVlPscaS3mSOCOQ";
    $accesstoken = "27026126-8tSI1JWQclqoSoynR9uUPL660ERcQcsZUwQ4HQOVc";
    $accesstokensecret = "n5fO4JGUaQ5wN1owJeMlofEYExQGJ6V4Ylh9ZeravfTVM";
    // Seconds to cache feed (Default : 1 minute).
    $cachetime = 60 * 3;
    // Time that the cache was last updtaed.
    $cache_file_created = file_exists($cache_file) ? filemtime($cache_file) : 0;
    // A flag so we know if the feed was successfully parsed.
    $tweet_found = false;
    // Show cached version of tweets, if it's less than $cachetime.
    if (time() - $cachetime < $cache_file_created) {
        $tweet_found = true;
        // Display tweets from the cache.
        readfile($cache_file);
    } else {
        // Cache file not found, or old. Authenticae app.
        $connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
        if ($connection) {
            // Get the latest tweets from Twitter
            $get_tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitter_user_id . "&count=" . $tweets_to_display . "&include_rts=" . $include_rts . "&exclude_replies=" . $ignore_replies);
            // Error check: Make sure there is at least one item.
            if (count($get_tweets)) {
                // Define tweet_count as zero
                $tweet_count = 0;
                // Start output buffering.
                ob_start();
                // Open the twitter wrapping element.
                $twitter_html = $twitter_wrap_open;
                // Iterate over tweets.
                foreach ($get_tweets as $tweet) {
                    $tweet_found = true;
                    $tweet_count++;
                    $tweet_desc = $tweet->text;
                    // Add hyperlink html tags to any urls, twitter ids or hashtags in the tweet.
                    $tweet_desc = preg_replace("/((http)+(s)?:\\/\\/[^<>\\s]+)/i", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $tweet_desc);
                    $tweet_desc = preg_replace("/[@]+([A-Za-z0-9-_]+)/", "<a href=\"http://twitter.com/\\1\" target=\"_blank\">\\0</a>", $tweet_desc);
                    $tweet_desc = preg_replace("/[#]+([A-Za-z0-9-_]+)/", "<a href=\"http://twitter.com/search?q=%23\\1\" target=\"_blank\">\\0</a>", $tweet_desc);
                    // Convert Tweet display time to a UNIX timestamp. Twitter timestamps are in UTC/GMT time.
                    $tweet_time = strtotime($tweet->created_at);
                    if ($twitter_style_dates) {
                        // Current UNIX timestamp.
                        $current_time = time();
                        $time_diff = abs($current_time - $tweet_time);
                        switch ($time_diff) {
                            case $time_diff < 60:
                                $display_time = $time_diff . ' seconds ago';
                                break;
                            case $time_diff >= 60 && $time_diff < 3600:
                                $min = floor($time_diff / 60);
                                $display_time = $min . ' minutes ago';
                                break;
                            case $time_diff >= 3600 && $time_diff < 86400:
                                $hour = floor($time_diff / 3600);
                                $display_time = $hour . ' hr';
                                if ($hour > 1) {
                                    $display_time .= 's';
                                }
                                $display_time .= ' ago';
                                break;
                            default:
                                $display_time = date($date_format, $tweet_time);
                                break;
                        }
                    } else {
                        $display_time = date($date_format, $tweet_time);
                    }
                    // Render the tweet.
                    // $twitter_html .= $tweet_wrap_open.$meta_wrap_open.'<a href="http://twitter.com/'.$twitter_user_id.'">@'.$display_time.'</a>'.html_entity_decode($tweet_desc).$meta_wrap_close.$tweet_wrap_close;
                    $twitter_html .= $tweet_wrap_open . $meta_wrap_open . '<a href="https://www.twitter.com/' . $twitter_user_id . '" target="blank">@' . $twitter_user_id . '</a>' . $time_open . $display_time . $time_close . $meta_wrap_close . html_entity_decode($tweet_desc) . $tweet_wrap_close;
                    // If we have processed enough tweets, stop.
                    if ($tweet_count >= $tweets_to_display) {
                        break;
                    }
                }
                // Close the twitter wrapping element.
                $twitter_html .= $twitter_wrap_close;
                echo $twitter_html;
                // Generate a new cache file.
                $file = fopen($cache_file, 'w');
                // Save the contents of output buffer to the file, and flush the buffer.
                fwrite($file, ob_get_contents());
                fclose($file);
                ob_end_flush();
            }
        }
    }
}
开发者ID:j2made,项目名称:Simple-Social-Stuff,代码行数:92,代码来源:twitter-get-recent.php


示例17: date_default_timezone_set

<?php

require_once 'config.inc.php';
require_once 'lib.php';
date_default_timezone_set('UTC');
// OAuth
require_once 'twitteroauth/twitteroauth.php';
function getConnectionWithAccessToken($oauth_token, $oauth_token_secret)
{
    global $config;
    $connection = new TwitterOAuth($config['consumer_key'], $config['consumer_secret'], $oauth_token, $oauth_token_secret);
    return $connection;
}
if ($config['oauth']) {
    $connection = getConnectionWithAccessToken($config['oauth_token'], $config['oauth_token_secret']);
} else {
}
$lastpublished = strtotime('10 September 2000');
$published = $lastpublished;
echo $lastpublished . "\n";
$filename = dirname(__FILE__) . '/published.json';
if (file_exists($filename)) {
    $file = @fopen($filename, "a+") or die("could't open file --\"{$filename}\"");
    $json = fread($file, filesize($filename));
    fclose($file);
    $lastpublished = json_decode($json);
    $published = $lastpublished;
}
echo "Last published={$lastpublished}\n";
echo "Published={$published}\n";
// Fetch feed
开发者ID:rdmpage,项目名称:bioguid,代码行数:31,代码来源:twitter.php


示例18: session_start

<?php

session_start();
require_once "twitteroauth/twitteroauth.php";
//Path to twitteroauth library
$twitteruser = "twitter-user-name";
$notweets = 30;
$consumerkey = "enter-consumerkey-here";
$consumersecret = "enter-consumersecret-here";
$accesstoken = "enter-accesstoken-here";
$accesstokensecret = "enter-accesstoken-here";
function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret)
{
    $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
    return $connection;
}
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitteruser . "&count=" . $notweets);
echo json_encode($tweets);
开发者ID:yabafinet,项目名称:midas-website,代码行数:19,代码来源:get-tweets.php


示例19: get_option

		<?php 
$gdl_show_twitter = get_option(THEME_SHORT_NAME . '_show_twitter_bar', 'enable') == 'enable' ? true : false;
$gdl_homepage_twitter = get_option(THEME_SHORT_NAME . '_show_twitter_only_homepage', 'disable') == 'enable' ? true : false;
if ($gdl_show_twitter && ($gdl_homepage_twitter && is_front_page() || !$gdl_homepage_twitter)) {
    $twitter_id = get_option(THEME_SHORT_NAME . '_twitter_bar_id');
    $num_fetch = get_option(THEME_SHORT_NAME . '_twitter_num_fetch');
    $consumer_key = get_option(THEME_SHORT_NAME . '_twitter_bar_consumer_id');
    $consumer_secret = get_option(THEME_SHORT_NAME . '_twitter_bar_consumer_secret');
    $access_token = get_option(THEME_SHORT_NAME . '_twitter_bar_access_token');
    $access_token_secret = get_option(THEME_SHORT_NAME . '_twitter_bar_access_token_secret');
    $cache_time = get_option(THEME_SHORT_NAME . '_twitter_bar_cache_time', '1');
    $last_cache_time = get_option(THEME_SHORT_NAME . '_twitter_bar_last_cache_time', 0);
    $diff = time() - $last_cache_time;
    $crt = $cache_time * 3600;
    if (empty($last_cache_time) || $diff >= $crt) {
        $connection = getConnectionWithAccessToken($consumer_key, $consumer_secret, $access_token, $access_token_secret);
        $tweets = $connection->get("htt 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP getConsumer函数代码示例发布时间:2022-05-15
下一篇:
PHP getConnection函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap