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; }
/** * request method for accessing twitter endpoints * * * @param string $url * @param string $method * @param array $fields * @return string * @throws Exception */ public function request($url, $method = 'POST', $fields = array()) { if (!isset($url)) { throw new Exception('SERVER: Unable to submit request to an empty URL.'); } if ($method == 'GET') { if (!empty($fields)) { $queryStr = http_build_query($fields); return $this->twitterAPIExchange->setGetfield($queryStr)->buildOauth($url, $method)->performRequest(); } } if ($method == 'POST') { return $this->twitterAPIExchange->buildOauth($url, $method)->setPostfields($fields)->performRequest(); } }
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; }
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'"); }
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); }
/** * 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! :( '); } }
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; }
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; }
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; }
/** * 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; }
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; }
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); }
/** * Index results * * @return void Redirects if request is not POST * @throws \LogicException When Twitter Configuration is not defined. */ public function results() { if ($this->request->is('post') && $this->request->data['search']) { // Limit search to 10 keywords (cf. Twitter bests practices) if (str_word_count($this->request->data['search']) > 10) { $this->Flash->error(__('Please Limit your search to 10 keywords')); return $this->redirect(['controller' => 'Pages', 'action' => 'home']); } // Settings TwitterAPIExchange $twitterAPI = new \TwitterAPIExchange(array('oauth_access_token' => Configure::read('twitter.oauth_access_token'), 'oauth_access_token_secret' => Configure::read('twitter.oauth_access_token_secret'), 'consumer_key' => Configure::read('twitter.consumer_key'), 'consumer_secret' => Configure::read('twitter.consumer_secret'))); // urlencode param $search = urlencode($this->request->data['search']); $result = json_decode($twitterAPI->setGetfield('?count=' . ($quantityByRequest = Configure::read('twitter.quantity_by_request') . '&q=' . $search . '&result_type=' . ($resultType = Configure::read('twitter.result_type'))))->buildOauth($url = Configure::read('twitter.url'), $requestMethod = Configure::read('twitter.request_method'))->performRequest(), true); $tweets = array(); if (isset($result['statuses']) && count($result['statuses']) !== 0) { $tweets = $result['statuses']; // get last id end($result['statuses']); $lastId = $result['statuses'][key($result['statuses'])]['id']; $tweets = $result['statuses']; // repeat action until $maxResult while (count($tweets) < ($maxResult = Configure::read('twitter.max_result'))) { // check quantity needed $quantity = $maxResult - count($tweets) > $quantityByRequest ? $quantityByRequest : $maxResult - count($tweets); $result = json_decode($twitterAPI->setGetfield('?count=' . $quantity . '&q=' . $search . '&result_type=' . $resultType . '&max_id=' . $lastId)->buildOauth($url, $requestMethod)->performRequest(), true); if (isset($result['statuses']) && count($result['statuses']) !== 0) { // get last id end($result['statuses']); $lastId = $result['statuses'][key($result['statuses'])]['id']; // merge data $tweets = array_merge($tweets, $result['statuses']); } else { break; } } // order data usort($tweets, array(&$this->Math, 'compare')); } elseif (isset($result['errors'])) { // API Rate limit exceeded $this->Flash->error(__('Rate limit exceeded. Please wait 15 min')); } $this->set(array('tweets' => $tweets, 'search' => $search)); } else { return $this->redirect(['controller' => 'Pages', 'action' => 'home']); } }
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; }
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; }
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); }
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; }
/** * 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)); }
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; }
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; }
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; }
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; }
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]; }
/** * 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; }
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; }
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; }
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 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); }
function sb_social_twitter($account, $limit = 10) { $settings = array("oauth_access_token" => TWITTER_OAUTH_TOKEN, "oauth_access_token_secret" => TWITTER_OAUTH_SECRET, "consumer_key" => TWITTER_CONSUMER_KEY, "consumer_secret" => TWITTER_CONSUMER_SECRET); $url = "https://api.twitter.com/1.1/statuses/user_timeline.json"; $options = "?screen_name=" . $account . "&count=" . $limit; $twitter = new TwitterAPIExchange($settings); $output = array(); if ($twitter) { $data = json_decode($twitter->setGetfield($options)->buildOauth($url, "GET")->performRequest()); foreach ($data as $status) { $output[] = array("source" => "twitter", "permalink" => "https://twitter.com/" . $status->user->screen_name . "/status/" . $status->id_str, "timestamp" => strtotime($status->created_at), "content" => $status->text, "image" => $status->entities->media[0]->media_url_https); } } return $output; }
/** * 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; }