示例#1
0
 public function getTweets($screen_name = '', $hastag = '', $count = '', $retweets = '')
 {
     // Include the OAuth API communications system
     // Twitter Launcher
     require_once 'TwitterAPIExchange.php';
     // Twitter API settings - Tskynet ( can't swing over due to phone being locked to ONE ACCOUNT ONLY )
     $settings = array('oauth_access_token' => "INSERTtoken", 'oauth_access_token_secret' => "INSERTsecret", 'consumer_key' => "INSERTkey", 'consumer_secret' => "INSERTCONSUMERsecret");
     // Instantiate a new instance
     $twitter = new TwitterAPIExchange($settings);
     // End point
     $url = 'https://api.twitter.com/1.1/search/tweets.json';
     // Select what we're searching for
     if ($screen_name) {
         $getfield = "?q=%3A" . urlencode($screen_name);
         $lastSeenID = $this->getLastSeenTwitterID($screen_name);
         if ($lastSeenID != "") {
             $getfield .= "&since_id=" . $lastSeenID;
         }
     } else {
         $getfield = "?q=%23" . urlencode($hastag);
     }
     // Using the search function we have to use the GET method
     $requestMethod = 'GET';
     // Create the OAuth request and grab the data
     $data = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
     // return the dataset to the calling area
     return json_decode($data);
 }
示例#2
0
function getLocationsOfHashtag($hashtag)
{
    require_once __DIR__ . '/config.php';
    $url = 'https://api.twitter.com/1.1/search/tweets.json';
    $getfield = '?lang=en&count=15&q=%40' . $hashtag;
    $requestMethod = 'GET';
    $twitter = new TwitterAPIExchange($twitterSettings);
    $response = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
    $result = json_decode($response, true);
    $cities = array();
    foreach ($result['statuses'] as $item) {
        if (!empty($item['user']['location'])) {
            $cities[] = $item['user']['location'];
        }
    }
    $locations = array();
    $googleKey = '&key=' . $googleSettings['server_key'];
    foreach ($cities as $city) {
        $response = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?address=" . urlencode($city) . $googleKey);
        $result = json_decode($response, true);
        foreach ($result['results'] as $item) {
            $item['geometry']['location']['city'] = $city;
            $locations[] = $item['geometry']['location'];
        }
    }
    return $locations;
}
示例#3
0
function recup_tweet($mc)
{
    require_once 'twitter_api/TwitterAPIExchange.php';
    /** Set access tokens here - see: https://dev.twitter.com/apps/ **/
    $settings = array('oauth_access_token' => "", 'oauth_access_token_secret' => "", 'consumer_key' => "", 'consumer_secret' => "");
    //$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
    $url = "https://api.twitter.com/1.1/search/tweets.json";
    $requestMethod = "GET";
    $getfield = '?q=' . $mc . '&lang=fr';
    $twitter = new TwitterAPIExchange($settings);
    $raw = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
    $raw = strstr($raw, 'metadata');
    $tab_tweet = array();
    while ($raw != null) {
        $raw = substr($raw, 8);
        $tmp = strstr($raw, 'metadata', true);
        array_push($tab_tweet, $tmp);
        $raw = strstr($raw, 'metadata');
    }
    unset($tab_tweet[count($tab_tweet) - 1]);
    unset($tab_tweet[count($tab_tweet) - 1]);
    //echo count($tab_tweet);
    $tab = array();
    $j = 1;
    $bdd = new PDO('mysql:host=localhost;dbname=projet;charset=utf8', 'root', 'root');
    foreach ($tab_tweet as $key => $value) {
        //Recherche de la date et de l'heure
        $tweet = array();
        $a = strstr($value, '{"created_at":"');
        $tmp = substr($a, 15, 30);
        $date = src_date($tmp);
        array_push($tweet, $date);
        //Recherche du pseudo
        $a = strstr($value, '","location":"', true);
        $a = strstr($a, '"screen_name"');
        $nom = substr($a, strlen('screen_namee":"'));
        array_push($tweet, $nom);
        //Recherche du tweet
        $a = strstr($value, '","text":"');
        $a = strstr($a, '","entities":', true);
        $text = uni_to_utf(substr($a, strlen('","text":"')));
        array_push($tweet, $text);
        array_push($tab, $tweet);
        $where = '`auteur` = "' . $tweet[1] . '" and `date` = "' . $tweet[0][0] . '" and `heure` = "' . $tweet[0][1] . '" and `post` = "' . $tweet[2] . '"';
        $sql = "SELECT * FROM `post` WHERE " . $where;
        $rep = $bdd->query($sql);
        $data = $rep->fetch();
        if ($data == null) {
            $tweet[2] = utf8_decode(utf8_encode($tweet[2]));
            $value = 'VALUES ("' . $tweet[1] . '", "' . $tweet[0][0] . '", "' . $tweet[0][1] . '" ,"' . $tweet[2] . '" ,"' . $tweet[0][2] . '")';
            $sql = "INSERT INTO `post`( `auteur`, `date`, `heure`, `post`, `strtotime`) " . $value;
            //echo $sql;
            $rep = $bdd->query($sql);
            //echo '<br/><br/>';
        }
        unset($tweet);
        $j++;
    }
    header("Refresh: 1;url='http://localhost/projet/maj2.php'");
}
示例#4
0
文件: CTwitter.php 项目: bravej/AARON
 public function afficher()
 {
     include 'TwitterTextFormatter.php';
     include 'TwitterAPIExchange.php';
     //twitter application tokens
     $settings = array('consumer_key' => 'X3CFmg15tOhI9Y7H0cGP3ylxX', 'consumer_secret' => 'I7gwqLDH9JnEAMlKGchzWzEaWVy3vUNDYM2kQQsk2ENqeWmmvG', 'oauth_access_token' => '3308186359-BUBd8phkNBNlT2JU8lnFctrlThCgrvJHGtDOZaL', 'oauth_access_token_secret' => 'pvSoe3K38JpiQqChz2DItL7NDwsO8alRuz5xnv9QOFU1Y');
     //timeline
     $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
     $getfield = "?screen_name={$this->screen_name}";
     $requestMethod = 'GET';
     $twitter = new TwitterAPIExchange($settings);
     $user_timeline = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
     $user_timeline = json_decode($user_timeline);
     $msg = "";
     if (isset($user_timeline[1]->user->profile_image_url)) {
         $media_url = $user_timeline[1]->user->profile_image_url;
         $msg .= "<img src='{$media_url}' width='10%' /> " . $user_timeline[1]->user->name . " @" . $user_timeline[1]->user->screen_name;
     }
     $msg .= "<hr />";
     foreach ($user_timeline as $user_tweet) {
         $msg .= TwitterTextFormatter::format_text($user_tweet) . "<br/>";
         if (isset($user_tweet->entities->media)) {
             $media_url = $user_tweet->entities->media[0]->media_url;
             $msg .= "<img src='{$media_url}' width='50%' />";
         }
         $msg .= "<hr />";
     }
     return $msg;
 }
示例#5
0
function postTwitter()
{
    $url = 'https://upload.twitter.com/1.1/media/upload.json';
    $requestMethod = 'POST';
    $settings = array('consumer_key' => "yyDZQ8MvKof6NKHjh15jrFu8I", 'consumer_secret' => "aY2RJcTyM7HVyyUXMIedrGEW3OVVwE1F4f4gnSMB0yrjZJnKMg", 'oauth_access_token' => "711228384077074432-zQwT4Xlvy1cuxBM6rtyUxJdPafrtDQh", 'oauth_access_token_secret' => "ZgSXDRYwXAPlS81HuRvJlouh5zWJJMK4niFzeLzAa7YAL");
    $postfields = array('media_data' => base64_encode(file_get_contents(getCaminhoImagem(getConnection()))));
    try {
        $twitter = new TwitterAPIExchange($settings);
        echo "Enviando imagem...\n";
        $retorno = $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest(true);
        echo $retorno . "\n";
        $retorno = json_decode($retorno);
        if (isset($retorno->error) && $retorno->error != "") {
            return false;
        }
        $url = 'https://api.twitter.com/1.1/statuses/update.json';
        $requestMethod = 'POST';
        /** POST fields required by the URL above. See relevant docs as above **/
        $postfields = array('status' => 'If you like SEXY GIRLS visit http://sluttyfeed.com/ - The best P**N on internet! - #p**n #adult #hot #xxx', 'media_ids' => $retorno->media_id_string);
        echo "\nPostando no twitter...\n";
        $retorno = $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
        echo $retorno . "\n";
        $retorno = json_decode($retorno);
        if (isset($retorno->errors)) {
            return false;
        }
        echo "Postado!\n";
        return true;
    } catch (Exception $ex) {
        echo $ex->getMessage();
        return false;
    }
}
示例#6
0
 function get_tweets()
 {
     global $cache;
     $age = 3600;
     //one hour
     if (isset($cache['twitter'])) {
         if ((int) $cache['twitter']['age'] + $age > time()) {
             $tweets = $cache['twitter'];
             unset($tweets['age']);
             return $tweets;
         }
     }
     $user = qa_opt('cs_twitter_id');
     $count = (int) qa_opt('cs_twitter_t_count');
     $title = qa_opt('cs_twitter_title');
     require_once Q_THEME_DIR . '/inc/TwitterAPIExchange.php';
     // Setting our Authentication Variables that we got after creating an application
     $settings = array('oauth_access_token' => qa_opt('cs_twitter_at'), 'oauth_access_token_secret' => qa_opt('cs_twitter_ts'), 'consumer_key' => qa_opt('cs_twitter_ck'), 'consumer_secret' => qa_opt('cs_twitter_cs'));
     $url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
     $requestMethod = "GET";
     $getfield = "?screen_name={$user}&count={$count}";
     $twitter = new TwitterAPIExchange($settings);
     $tweets = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), $assoc = TRUE);
     //$tweets = array(array('text' => "hello @towhidn"));
     $cache['twitter'] = $tweets;
     $cache['twitter']['age'] = time();
     $cache['changed'] = true;
     return $tweets;
 }
示例#7
0
function GetTweetsByURL()
{
    //Include Twitter tokens file
    include "TWInfo.php";
    // Setup the Get URL
    $url = 'https://api.twitter.com/1.1/search/tweets.json';
    // The request method, according to the docs, is GET, not POST
    $requestMethod = 'GET';
    // Get hashtag from URL and set up the string
    $hashtag = strval($_GET['h']);
    // Get twitter account from URL and set up the string
    $TW_Account = strval($_GET['ta']);
    if (strlen($TW_Account) > 0) {
        $TW_Account = "%20%40" . $TW_Account;
    }
    // %20 = SPACE, %40 = "AT" SYMBOL (@)
    $getfield = '?q=%23' . $hashtag . $TW_Account;
    // %23 = #
    // Create the object
    $twitter = new TwitterAPIExchange($settings);
    // Make the request and get the response into the $json variable
    $json = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
    // It's json, so decode it into an array
    $result = json_decode($json, true);
    // Access the profile_image_url element in the array
    return $result;
    echo $getfield;
}
示例#8
0
/**
 * Fetches a list of tweets
 */
function fsp_fetch_twitter()
{
    // Require the Twitter PHP API
    require_once 'twitter-api-php/TwitterAPIExchange.php';
    // set access tokens
    $settings = array('oauth_access_token' => SSF_TWITTER_OAUTH_TOKEN, 'oauth_access_token_secret' => SSF_TWITTER_OAUTH_SECRET, 'consumer_key' => SSF_TWITTER_CONSUMER_KEY, 'consumer_secret' => SSF_TWITTER_CONSUMER_SECRET);
    $twitter = new TwitterAPIExchange($settings);
    $params = "?screen_name=" . SSF_TWITTER_USERNAME;
    $response = $twitter->setGetfield($params)->buildOauth('https://api.twitter.com/1.1/statuses/user_timeline.json', 'GET')->performRequest();
    $response = json_decode($response);
    $items = array();
    foreach ($response as $tweet) {
        $item = array();
        $item['type'] = 'twitter';
        $item['source'] = 'https://twitter.com/' . $tweet->user->screen_name . '/status/' . $tweet->id;
        $item['uid'] = $tweet->id;
        $item['created'] = strtotime($tweet->created_at);
        $item['title'] = wp_trim_words($tweet->text, 6);
        $item['content'] = $tweet->text;
        // tweet might have an image
        if (isset($tweet->extended_entities->media) && $tweet->extended_entities->media[0]->type == 'photo') {
            $item['image'] = $tweet->extended_entities->media[0]->media_url_https;
        }
        $items[] = $item;
    }
    return $items;
}
 public function getFollowers($screen_name)
 {
     $twitter = new TwitterAPIExchange($this->settings);
     $getfield = array('screen_name' => $screen_name, 'cursor' => -1);
     $followers = array();
     while ($getfield['cursor'] != 0) {
         // Check for when we can get the next set of followers.
         $response = $twitter->setGetfield('resources=' . $this->twFollowers['resource'])->buildOauth($this->twRate['url'], $this->twRate['method'])->performRequest();
         $rate = json_decode($response);
         // If we are close to the limit, wait until the reset time.
         if ($rate->resources->followers->{'/followers/ids'}->remaining <= 2) {
             $sleepTime = $rate->resources->followers->{'/followers/ids'}->reset - time();
             echo 'Nearing rate limit, waiting ' . $sleepTime . " seconds.\n";
             sleep($sleepTime);
         }
         // Request the set of followers.
         $response = $twitter->setGetfield(http_build_query($getfield))->buildOauth($this->twFollowers['url'], $this->twFollowers['method'])->performRequest();
         $json = json_decode($response);
         // Return if there are errors.
         if (!empty($json->errors)) {
             foreach ($json->errors as $error) {
                 echo "{$error->message}\n";
             }
             return;
         }
         // Add followers to results and iterate cursor.
         echo 'Adding ' . count($json->ids) . ' followers to ' . $screen_name . "\n";
         $followers = array_merge($followers, $json->ids);
         $getfield['cursor'] = $json->next_cursor;
     }
     return $followers;
 }
示例#10
0
function get_twt($settings, $getfield, $url)
{
    $requestMethod = 'GET';
    $twitter = new TwitterAPIExchange($settings);
    $tweets = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), true);
    return $tweets;
}
/**
 * Tutorial: Twitter feed com jQuery e PHP (api 1.1)
 *
 * @author   Fernando Moreira <*****@*****.**>
 * @license  MIT License
 * @link     http://nandomoreira.me/twitter-feed-com-jquery-e-php-api-1-1/
 */
function twitter_feed()
{
    global $url, $settings, $requestMethod, $getfield;
    $twitter = new TwitterAPIExchange($settings);
    $tw_data = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), true);
    if ($tw_data) {
        if ($tw_data["errors"][0]["message"] != "") {
            echo "<h3>Desculpe, ocorreu um problema.</h3><p>Twitter retornou a seguinte mensagem de erro:</p><p><em>" . $tw_data[errors][0]["message"] . "</em></p>";
            exit;
        } else {
            $twt_data = array();
            foreach ($tw_data as $i => $tw) {
                $twt_data[$i]['date'] = twitter_date_format($tw['created_at']);
                $twt_data[$i]['id'] = $tw['id'];
                $twt_data[$i]['avatar'] = $tw['user']['profile_image_url'];
                $twt_data[$i]['user'] = $tw['user']['screen_name'];
                $twt_data[$i]['text'] = $tw['text'];
                $twt_data[$i]['favorite_count'] = $tw['favorite_count'];
                $twt_data[$i]['retweet_count'] = $tw['retweet_count'];
            }
            return $twt_data;
        }
    } else {
        die('Problema: O twitter nao retornou nada! :( ');
    }
}
示例#12
0
文件: main.php 项目: MxAR/SGP
function api_req($qstring, $since, $apiSettings)
{
    $url = 'https://api.twitter.com/1.1/search/tweets.json';
    $getfield = '?q=' . $qstring . '+since:' . $since . '&lang=en&result_type=recent&count=50';
    $requestMethod = 'GET';
    $twitter = new TwitterAPIExchange($apiSettings);
    return json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), true);
}
示例#13
0
 private function downloadFreshTweets($settings)
 {
     $url = 'https://api.twitter.com/1.1/search/tweets.json';
     $getfield = '?count=100&q=%23openaccess%20-RT';
     $requestMethod = 'GET';
     $twitter = new TwitterAPIExchange($settings);
     $tweets_json = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
     return $tweets_json;
 }
示例#14
0
 public function mentions_timeline()
 {
     $twitter = new TwitterAPIExchange($this->settings);
     $url = "https://api.twitter.com/1.1/statuses/mentions_timeline.json";
     $requestMethod = "GET";
     $getfield = "?count=50";
     $data = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), $assoc = TRUE);
     return $data;
 }
 public function getProjectTweets($hashtag)
 {
     $settings = array('oauth_access_token' => $_ENV['TWITTER_ACCESS_TOKEN'], 'oauth_access_token_secret' => $_ENV['TWITTER_SECRET_ACCESS_TOKEN'], 'consumer_key' => $_ENV['TWITTER_CUSTOMER_KEY'], 'consumer_secret' => $_ENV['TWITTER_CUSTOMER_SECRET']);
     $url = 'https://api.twitter.com/1.1/search/tweets.json';
     $getfield = '?q=' . $hashtag;
     $requestMethod = 'GET';
     $twitter = new TwitterAPIExchange($settings);
     $tweets = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
     return $tweets;
 }
 private function getRequest($url, $params = array())
 {
     $getfield = '?';
     foreach ($params as $key => $value) {
         $getfield .= '&' . $key . '=' . $value;
     }
     $twitter = new TwitterAPIExchange($this->creds['oauth']);
     $response = $twitter->setGetfield($getfield)->buildOauth($url, 'GET')->performRequest();
     return json_decode($response);
 }
示例#17
0
 /**
  * Get user twitts
  */
 public function getTwits()
 {
     $settings = array('oauth_access_token' => $this->access_token, 'oauth_access_token_secret' => $this->access_token_secret, 'consumer_key' => $this->consumer_key, 'consumer_secret' => $this->consumer_secret);
     $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
     $getfield = '?screen_name=' . $this->username;
     $requestMethod = 'GET';
     $twitter = new \TwitterAPIExchange($settings);
     $response = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
     var_dump(json_decode($response));
 }
function follow($usuario)
{
    ini_set('display_errors', 1);
    require_once 'plugins/twitter-api-exchange/TwitterAPIExchange.php';
    $settings = array('oauth_access_token' => get_option("access_token"), 'oauth_access_token_secret' => get_option("access_token_secret"), 'consumer_key' => get_option("consumer_key"), 'consumer_secret' => get_option("consumer_secret"));
    $url = 'https://api.twitter.com/1.1/friendships/create.json';
    $requestMethod = 'POST';
    $postfields = array('screen_name' => $usuario, 'follow' => "true");
    $twitter = new TwitterAPIExchange($settings);
    return $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
}
 function quan_tweet_get_tweets($api_settings)
 {
     $user = get_field('quan_tweet_twitter_username', 'option');
     // $since_id = get_option( 'quan_tweet_latest' ); &since_id={$since_id}
     $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
     $getfield = "?screen_name={$user}";
     $requestMethod = 'GET';
     $twitter = new TwitterAPIExchange($api_settings);
     $response = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), $assoc = TRUE);
     return $response;
 }
示例#20
0
 private static function fetch($url, $getfield)
 {
     $requestMethod = 'GET';
     $twitter = new \TwitterAPIExchange(self::$settings);
     $data = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
     $data = json_decode($data, true);
     if (array_key_exists('errors', $data)) {
         throw new \deco\essentials\exception\General(array('dict' => 'TWITTER.RATE_LIMIT_EXCEEDED', 'param' => array('code' => $data['errors'][0]['code'], 'reply' => json_encode($data, JSON_PRETTY_PRINT)), 'msg' => $data['errors'][0]['message']));
     }
     return $data;
 }
 private function getTweets($searchTerm, $result_type, $count)
 {
     $settings = array('oauth_access_token' => Config::get('oauth.oauth_access_token'), 'oauth_access_token_secret' => Config::get('oauth.oauth_access_token_secret'), 'consumer_key' => Config::get('oauth.consumer_key'), 'consumer_secret' => Config::get('oauth.consumer_secret'));
     $url = 'https://api.twitter.com/1.1/search/tweets.json';
     $getfield = '?q=' . $searchTerm . '&result_type=' . $result_type . '&count=' . $count . '&src=typd';
     $requestMethod = 'GET';
     $twitter = new TwitterAPIExchange($settings);
     $jsonResponse = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
     $results = json_decode($jsonResponse);
     return $results;
 }
示例#22
0
 function getTweets($user)
 {
     ini_set('display_errors', 1);
     require_once 'TwitterAPIExchange.php';
     $settings = array('oauth_access_token' => "Tu token ", 'oauth_access_token_secret' => "Tu token Secret", 'consumer_key' => "Tu consumer_key", 'consumer_secret' => "Tu consumer_secret");
     $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
     $getfield = '?screen_name=' . $user . '&count=100';
     $requestMethod = 'GET';
     $twitter = new TwitterAPIExchange($settings);
     $json = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
     return $json;
 }
示例#23
0
 /**
  * Загрузка изображений
  * $file - путь к загружаемому файлу
  */
 public function uploadImg($file)
 {
     $file = file_get_contents(MODX_BASE_PATH . $file);
     $data = base64_encode($file);
     $url = 'https://upload.twitter.com/1.1/media/upload.json';
     $requestMethod = 'POST';
     $postfields = array('media_data' => $data);
     $twitter = new TwitterAPIExchange($this->twKeys);
     $request = $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
     $response = json_decode($request);
     return $response;
 }
 public function twitter_count($user, $countItem = '')
 {
     /** Set access tokens here - see: https://dev.twitter.com/apps/ **/
     $settings = array('oauth_access_token' => env('TWITTER_ACCESS_TOKEN'), 'oauth_access_token_secret' => env('TWITTER_ACCESS_TOKEN_SECRET'), 'consumer_key' => env('TWITTER_CONSUMER_KEY'), 'consumer_secret' => env('TWITTER_CONSUMER_SECRET'));
     $url = 'https://api.twitter.com/1.1/users/show.json';
     $getfield = '?screen_name=' . $user;
     $requestMethod = 'GET';
     $twitter = new TwitterAPIExchange($settings);
     $follow_count = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
     $get_count = json_decode($follow_count, true);
     $countItem = $countItem != '' ? $countItem : 'followers_count';
     return $get_count[$countItem];
 }
示例#25
0
 /**
  * Making request to Twitter API
  */
 public function twitter_timeline($username, $limit, $oauth_access_token, $oauth_access_token_secret, $consumer_key, $consumer_secret)
 {
     require_once 'TwitterAPIExchange.php';
     /** Set access tokens here - see: https://dev.twitter.com/apps/ */
     $settings = array('oauth_access_token' => $oauth_access_token, 'oauth_access_token_secret' => $oauth_access_token_secret, 'consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret);
     $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
     $getfield = '?screen_name=' . $username . '&count=' . $limit;
     $request_method = 'GET';
     $twitter_instance = new TwitterAPIExchange($settings);
     $query = $twitter_instance->setGetfield($getfield)->buildOauth($url, $request_method)->performRequest();
     $timeline = json_decode($query);
     return $timeline;
 }
示例#26
0
 protected function getTrimmedTwitterResponse(\TwitterAPIExchange $twitter, array $showOnlyFields)
 {
     $url = 'https://api.twitter.com/1.1/users/show.json';
     $fields = '?screen_name=' . getenv('TW_ACCOUNT_NAME');
     $requestMethod = 'GET';
     $result = $twitter->setGetfield($fields)->buildOauth($url, $requestMethod)->performRequest(true, array(CURLOPT_SSL_VERIFYPEER => false));
     $trimmedResult = [];
     foreach ($showOnlyFields as $field) {
         if (array_key_exists($field, $jsonAsArray = json_decode($result, true))) {
             $trimmedResult[$field] = $jsonAsArray[$field];
         }
     }
     return $trimmedResult;
 }
示例#27
0
function curl($url)
{
    $settings = array('oauth_access_token' => "2328160578-tOM7fM8a3BqRTOLsddC4Pv7sw8Y5tFg0DcOMYoG", 'oauth_access_token_secret' => "AXjA9BWCCJP81VvY5OWSYA5RyZpdV4C88j3T1lgYbmHOn", 'consumer_key' => "stevenaylin", 'consumer_secret' => "2328160578");
    $url = 'https://api.twitter.com/1.1/blocks/create.json';
    $getfield = '?screen_name=stevenaylin&count=2';
    $requestMethod = 'GET';
    $twitter = new TwitterAPIExchange($settings);
    $response = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
    return json_decode($response);
    //    $c = curl_init($url);
    //    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    //    curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 1);
    //    curl_setopt($c, CURLOPT_TIMEOUT, 1);
}
示例#28
0
 function getTweets($user)
 {
     ini_set('display_errors', 1);
     require_once 'TwitterAPIExchange.php';
     $settings = array('oauth_access_token' => "1898038981-H5XxQBmicDj32sfC22gn2jIXl9PAtN5VFry3p1z", 'oauth_access_token_secret' => "Yu6UZv3gk19B4jzXGGQQgDpE18jjFNOJoZvcGNRYmTOST", 'consumer_key' => "yRehIiKnmfNz8gY3RxiYtc3dz", 'consumer_secret' => "zH7aZcvoBdC2mzuupdJ55QJKRgiL5dOp21m1EaQUyuQlQkgUBp");
     //url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
     $url = 'https://api.twitter.com/1.1/search/tweets.json';
     //getfield = '?screen_name='.$user.'&count=100';
     $getfield = '?q=' . $user . '&count=100';
     $requestMethod = 'GET';
     $twitter = new TwitterAPIExchange($settings);
     $json = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
     return $json;
 }
function UpdateTimeline()
{
    global $settings;
    /** Perform a GET request and echo the response **/
    $url = 'https://api.twitter.com/1.1/statuses/home_timeline.json';
    $getfield = '?count=30';
    $requestMethod = 'GET';
    $twitter = new TwitterAPIExchange($settings);
    $timeline = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
    //save to cache
    UpdateCache($timeline);
    //echo results;
    echo $timeline;
}
示例#30
-1
 /**
  * Render method
  * @return var $output
  */
 public function render()
 {
     $screenName = $this->arguments['screen-name'];
     $count = $this->arguments['count'];
     $settings = $this->viewHelperVariableContainer->get('Tx_MooxSocial_ViewHelpers_TwitterViewHelper', 'twitter');
     $twitter = new TwitterAPIExchange($settings);
     $url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
     $requestMethod = "GET";
     $getfield = '?screen_name=' . $screenName . '&count=' . $count;
     $string = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), $assoc = TRUE);
     if ($string["errors"][0]["message"] != "") {
         $output = "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error message:</p><p><em>" . $string[errors][0]["message"] . "</em></p>";
         exit;
     } else {
         foreach ($string as $items) {
             $output .= "Time and Date of Tweet: " . $items['created_at'] . "<br />";
             $output .= "Tweet: " . $items['text'] . "<br />";
             $output .= "Tweeted by: " . $items['user']['name'] . "<br />";
             $output .= "Screen name: " . $items['user']['screen_name'] . "<br />";
             $output .= "Followers: " . $items['user']['followers_count'] . "<br />";
             $output .= "Friends: " . $items['user']['friends_count'] . "<br />";
             $output .= "Listed: " . $items['user']['listed_count'] . "<br /><hr />";
         }
     }
     return $output;
 }