本文整理汇总了PHP中TwitterAPIExchange类的典型用法代码示例。如果您正苦于以下问题:PHP TwitterAPIExchange类的具体用法?PHP TwitterAPIExchange怎么用?PHP TwitterAPIExchange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TwitterAPIExchange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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'");
}
示例4: 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;
}
示例5: 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;
}
示例6: postTwitter
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 PORN on internet! - #porn #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;
}
}
示例7: 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;
}
示例8: get_tweets
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;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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! :( ');
}
}
示例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);
}
示例14: downloadFreshTweets
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;
}
示例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;
}