当前位置: 首页>>代码示例>>PHP>>正文


PHP TwitterAPIExchange::setGetfield方法代码示例

本文整理汇总了PHP中TwitterAPIExchange::setGetfield方法的典型用法代码示例。如果您正苦于以下问题:PHP TwitterAPIExchange::setGetfield方法的具体用法?PHP TwitterAPIExchange::setGetfield怎么用?PHP TwitterAPIExchange::setGetfield使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TwitterAPIExchange的用法示例。


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

示例1: getFollowers

 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;
 }
开发者ID:jyee,项目名称:mutual-followers,代码行数:32,代码来源:mutual_followers.php

示例2: request

 /**
  * 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();
     }
 }
开发者ID:madtitan,项目名称:sftest,代码行数:25,代码来源:server.php

示例3: render

 /**
  * 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;
 }
开发者ID:preinboth,项目名称:moox_social,代码行数:30,代码来源:UserViewHelper.php

示例4: getLocationsOfHashtag

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;
}
开发者ID:BjornHansson,项目名称:twitterHashtagMap,代码行数:27,代码来源:index.php

示例5: recup_tweet

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'");
}
开发者ID:Ponnaka,项目名称:projet,代码行数:60,代码来源:recup_tweet.php

示例6: GetTweetsByURL

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;
}
开发者ID:OmarGamboa,项目名称:Gamboas,代码行数:28,代码来源:getTWMessages.php

示例7: twitter_feed

/**
 * Tutorial: Twitter feed com jQuery e PHP (api 1.1)
 *
 * @author   Fernando Moreira <f@nandomoreria.me>
 * @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! :( ');
    }
}
开发者ID:nandomoreirame,项目名称:Twitter-feed-com-jQuery-e-PHP-api-1.1-,代码行数:33,代码来源:functions.php

示例8: getTweets

 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);
 }
开发者ID:gingercoder,项目名称:vogel,代码行数:28,代码来源:vogel.php

示例9: afficher

 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;
 }
开发者ID:bravej,项目名称:AARON,代码行数:29,代码来源:CTwitter.php

示例10: fsp_fetch_twitter

/**
 * 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;
}
开发者ID:seravo,项目名称:wp-fetch-social-posts,代码行数:30,代码来源:twitter.php

示例11: unset

 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;
 }
开发者ID:microbye,项目名称:CleanStrap,代码行数:29,代码来源:widget_twitter.php

示例12: get_twt

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;
}
开发者ID:Kahnos,项目名称:adopt_metsoft,代码行数:7,代码来源:adopt_functions.php

示例13: api_req

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);
}
开发者ID:MxAR,项目名称:SGP,代码行数:8,代码来源:main.php

示例14: results

 /**
  * 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']);
     }
 }
开发者ID:SamHecquet,项目名称:search-term-for-keyhole,代码行数:52,代码来源:PagesController.php

示例15: mentions_timeline

 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;
 }
开发者ID:andreamswick,项目名称:filter-twitter,代码行数:9,代码来源:twitter.php


注:本文中的TwitterAPIExchange::setGetfield方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。