本文整理汇总了PHP中TwitterOAuth::get方法的典型用法代码示例。如果您正苦于以下问题:PHP TwitterOAuth::get方法的具体用法?PHP TwitterOAuth::get怎么用?PHP TwitterOAuth::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwitterOAuth
的用法示例。
在下文中一共展示了TwitterOAuth::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test
public function test()
{
$aModel = TuiyoLoader::model("applications", true);
$aUser = TuiyoAPI::get("user", null);
$aDocument = TuiyoAPI::get("document", null);
$aParams = $aModel->getSingleUserPlugin($aUser->id, "twitter");
if (!is_object($aParams)) {
$aDocument->enqueMessage(_("Cannot Load the service for this user"), "error");
return false;
}
echo $aParams->get("oauth_verifier");
/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$view =& $this->getView("twitter", "html");
/* Get temporary credentials. */
$access_token = $connection->getAccessToken($aParams->get('oauth_verifier', false));
/* Create a TwitterOauth object with consumer/user tokens. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
/* If method is set change API call made. Test is called by default. */
$content = $connection->get('account/verify_credentials');
//print_R($content);
$user = $connection->get('account/verify_credentials');
$userPublicFeeds = $connection->get('statuses/public_timeline');
print_R($userPublicFeeds);
}
示例2: get
protected function get($url, array $params = null)
{
$result = $this->oauth->get($url, $params);
if (isset($result->errors)) {
foreach ($result->errors as $error) {
throw new TwitterException($error->message, $error->code);
}
}
return $result;
}
示例3: updateTwitter
function updateTwitter($db, $twitter, $hashtag)
{
$db_con = mysqli_connect($db['host'], $db['user'], $db['password'], $db['name']);
$connection = new TwitterOAuth($twitter['consumer_key'], $twitter['consumer_secret'], $twitter['access_token'], $twitter['access_token_secret']);
$content['twitter'] = $connection->get("search/tweets", array('q' => '#' . $hashtag . ' filter:images', 'since_id' => $twitter['last_id'], 'include_entities' => true, 'lang' => 'en', 'count' => 100));
$content['vine'] = $connection->get("search/tweets", array('q' => '#' . $hashtag . ' vine.co filter:links', 'since_id' => $twitter['last_id'], 'include_entities' => true, 'lang' => 'en', 'count' => 100));
foreach ($content as $name => $media) {
if (isset($media->statuses)) {
foreach ($media->statuses as $tweet) {
if ($tweet->id > $twitter['last_id'] && (!empty($tweet->entities->urls) || isset($tweet->entities->media))) {
$twitter_id = $tweet->id;
$tweet_id = $tweet->id_str;
$created_at = $tweet->created_at;
$user_id = $tweet->user->id;
$this_name = mysqli_real_escape_string($db_con, stripEmojis($tweet->user->name));
$screen_name = mysqli_real_escape_string($db_con, $tweet->user->screen_name);
$user_location = mysqli_real_escape_string($db_con, stripEmojis($tweet->user->location));
$text = mysqli_real_escape_string($db_con, stripEmojis($tweet->text));
$link_post = 'https://twitter.com/' . $screen_name . '/status/' . $tweet_id;
$time_now = time();
$is_vine = false;
$is_tweet = false;
$type = 'photo';
if ($name == 'twitter' && isset($tweet->entities->media)) {
$is_tweet = true;
$media_url = $tweet->entities->media[0]->media_url;
$media_url_https = $tweet->entities->media[0]->media_url_https;
} else {
if (strpos($tweet->entities->urls[0]->expanded_url, 'vine.co') !== false && $name == 'vine' && !empty($tweet->entities->urls) && isset($tweet->entities->urls[0]->expanded_url)) {
$is_vine = true;
$type = 'video';
$media_url = $tweet->entities->urls[0]->expanded_url;
$dom = new DomFinder($media_url);
$video_cell = $dom->find("//meta[@property='twitter:player:stream']", 'content');
$picture_cell = $dom->find("//meta[@property='twitter:image']", 'content');
$media_url = $picture_cell[0];
$media_url_https = $video_cell[0];
}
}
if ($is_tweet || $is_vine) {
if (mysqli_query($db_con, "insert into media (time_now, source_id, created_at, user_id, name, screen_name, user_location, text, media_url, media_url_https, source, type, hashtag, post_url) " . "values('{$time_now}', '{$twitter_id}', '{$created_at}','{$user_id}','{$this_name}','{$screen_name}', '{$user_location}', '{$text}', '{$media_url}', '{$media_url_https}', 'twitter', '{$type}', '{$hashtag}', '{$link_post}')")) {
}
}
}
}
}
}
mysqli_close($db_con);
}
示例4: render_instance
public static function render_instance(BlockInstance $instance, $editing = false)
{
$configdata = $instance->get('configdata');
require_once 'twitter_api/twitteroauth.php';
require_once 'twitter_api/config.php';
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$result = '';
if (isset($configdata['widget'])) {
switch ($configdata['widget']) {
case "tweet":
if (isset($configdata['twitter_id'])) {
$data = $connection->get('statuses/show/' . $configdata['twitter_id'], '', 'tweet');
if (isset($data->error)) {
switch ($data->error) {
case "Not found":
return get_string('error_404_id', 'blocktype.twitter');
break;
default:
return get_string('error', 'blocktype.twitter');
break;
}
} else {
if (isset($data->id)) {
$result = self::create_single_tweet($configdata['twitter_id'], $data);
}
}
}
break;
case "timeline":
if (isset($configdata['twitter_screen_name'])) {
$data = $connection->get('statuses/user_timeline.json?screen_name=' . $configdata['twitter_screen_name'] . "&count=5", '', 'timeline');
if (isset($data->error)) {
switch ($data->error) {
case "Not found":
return get_string('error_404_tl', 'blocktype.twitter');
break;
default:
return get_string('error', 'blocktype.twitter');
break;
}
} else {
$result = self::create_timeline($data);
}
}
break;
}
}
return $result;
}
示例5: sendTweetByUser
function sendTweetByUser($event, $alertPeriod)
{
require_once TWOAUTH_CLASS_PATH . '/twitteroauth.php';
$systemMessages = '<div id="systemMessageHeader">';
stringDump($event);
// Build Tweet message up
if (isset($event['url'])) {
$url = "http://api.bit.ly/v3/shorten?login=" . DEFAULT_BITLY_LOGIN . "&apiKey=" . DEFAULT_BITLY_API_KEY . "&longUrl=" . urlencode($event['url']) . "&format=txt&history=1";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$surl = curl_exec($curl);
$last_response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
}
switch ($alertPeriod) {
case 24:
$tPeriod = 'in 24 hours';
break;
case 1:
$tPeriod = 'in 1 hour';
break;
case 0:
$tPeriod = 'now';
break;
}
if (isset($event['summary'])) {
$tweet = $event['summary'] . ' ';
} else {
$tweet = 'Event ';
}
$tweet .= $tPeriod;
if (isset($event['location'])) {
// Reverse Geo Lookup if no geo data attached to ics file
$tweet .= ' at ' . substr($event['location'], 0, 20);
if (isset($event['latitude']) && isset($event['longitude'])) {
$parameters = array('lat' => $event['latitude'], 'long' => $event['longitude']);
}
}
if (isset($surl)) {
$tweet .= ', see ' . $surl;
}
$tweet .= ' #twical';
stringDump($tweet);
/* Create a TwitterOauth object with consumer/user tokens. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $event['twitter_token'], $event['twitter_secret']);
/* If method is set change API call made. Test is called by default. */
$content = $connection->get('account/rate_limit_status');
$systemMessages .= '<span class="notice">Current API hits remaining: ' . $content->remaining_hits . '</span>';
$systemMessages .= '<span class="notice">Number of tweets to send out: ' . count($event) . '</span>';
$parameters['status'] = $tweet;
$content = $connection->post('statuses/update', $parameters);
stringDump($content);
if (isset($content->{'error'})) {
$systemMessages .= '<p class="failureMessage">' . $content->{'error'} . '</p>';
} else {
$systemMessages .= '<p class="notice"> Status ID:' . $content->{'id'} . ' <br/> Geo Enabled: ' . $content->{'user'}->{'geo_enabled'} . '<br /> Text Sent' . $content->{'text'} . '</p>';
}
return $systemMessages;
}
示例6: updateTwitterFeed
function updateTwitterFeed($lastupdate)
{
// Twitter!
global $preferences;
global $twit;
require_once 'oauth/twitteroauth.php';
$twit = new TwitterOAuth($preferences->CONSUMER_KEY, $preferences->CONSUMER_SECRET_KEY, $preferences->OAUTH_TOKEN, $preferences->OAUTH_SECRET_TOKEN);
// Update the following/followed balance
updateTwitterFollowing();
// Update user information for those who require it
updateTwitterUsers();
// Get mentions since the last update
$args = array();
$lastreadid = getPreference("last_twitter_id");
if ($lastreadid) {
$args['since_id'] = $lastreadid;
}
$tweets = $twit->get('statuses/mentions_timeline', $args);
// if we have no tweets, stop here
if (!is_array($tweets)) {
loginfo("No tweets to read!");
return false;
}
// process tweets individually
uasort($tweets, 'cmpTweetId');
foreach ($tweets as $tweet) {
$lastreadid = processTweet($tweet);
}
// Save the last updated tweet id
setPreference("last_twitter_id", $lastreadid);
return true;
}
示例7: get_tweets_from_api
private function get_tweets_from_api($username, $args)
{
if (!class_exists('TwitterOAuth')) {
//you need to reference the TwitterOAuth class for this to work
$this->error = 'The TwitterOAuth class cannot be found. Please include twitteroauth.php!';
return false;
}
$twitter_oauth = new TwitterOAuth($this->consumer_key, $this->consumer_secret, $this->access_key, $this->access_secret);
//setup params
$params = array();
$params['screen_name'] = strip_tags(sanitize_user($username));
if (array_key_exists('limit', $args)) {
$params['count'] = intval($args['limit']);
}
if (array_key_exists('include_rts', $args)) {
$params['include_rts'] = $args['include_rts'];
}
if (array_key_exists('exclude_replies', $args)) {
$params['exclude_replies'] = $args['exclude_replies'];
}
$response = $twitter_oauth->get('statuses/user_timeline', $params);
if (is_wp_error($response)) {
$this->error = $response->get_error_message();
return false;
} else {
if (isset($response->errors)) {
$this->error = $response->errors;
return false;
} else {
return $response;
}
}
}
示例8: update_twitter
public function update_twitter()
{
$consumer_key = ESSBSocialFollowersCounterHelper::get_option('twitter_consumer_key');
$consumer_secret = ESSBSocialFollowersCounterHelper::get_option('twitter_consumer_secret');
$access_token = ESSBSocialFollowersCounterHelper::get_option('twitter_access_token');
$access_token_secret = ESSBSocialFollowersCounterHelper::get_option('twitter_access_token_secret');
$id = ESSBSocialFollowersCounterHelper::get_option('twitter_id');
if (empty($consumer_key) || empty($consumer_secret) || empty($access_token) || empty($access_token_secret) || empty($id)) {
return 0;
}
if (!class_exists('TwitterOAuth')) {
include_once ESSB3_PLUGIN_ROOT . 'lib/modules/social-followers-counter/twitter/twitteroauth.php';
}
$api = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);
$response = $api->get('users/lookup', array('screen_name' => trim($id)));
if (isset($response->errors)) {
return null;
}
if (isset($response[0]) && is_array($response[0])) {
return $response[0]['followers_count'];
}
if (isset($response[0]->followers_count)) {
return $response[0]->followers_count;
}
}
示例9: twiget_get_tweets
/**
* Authenticate to Twitter using oAuth, and retrieve tweets
*/
function twiget_get_tweets()
{
require_once TWIGET_PLUGIN_PATH . '/lib/twitteroauth.php';
$twiget_options = get_option('twiget_options');
$defaults = array('user_id' => NULL, 'screen_name' => NULL, 'since_id' => NULL, 'count' => 5, 'max_id' => NULL, 'trim_user' => NULL, 'exclude_replies' => NULL, 'include_rts' => NULL, 'contributor_details' => NULL, 'widget_id' => NULL);
$options = array_intersect_key(array_merge($defaults, $_POST), $defaults);
$cache_period = $twiget_options['cache_period'] ? $twiget_options['cache_period'] : ceil(15 * 60 / 180 * twiget_count_instances());
$cache_disabled = $cache_period == 0 ? true : false;
if (!$cache_disabled) {
$tweets = get_transient('tweets-' . $options['widget_id']);
} else {
$tweets = false;
}
if ($tweets === false) {
$consumerkey = $twiget_options['consumer_key'];
$consumersecret = $twiget_options['consumer_secret'];
$accesstoken = $twiget_options['access_token'];
$accesstokensecret = $twiget_options['access_token_secret'];
session_start();
$connection = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets = $connection->get('https://api.twitter.com/1.1/statuses/user_timeline.json?' . http_build_query($options));
$tweets = json_encode($tweets);
if (!$cache_disabled) {
set_transient('tweets-' . $options['widget_id'], $tweets, $cache_period);
}
}
echo $tweets;
exit;
}
示例10: TwitterData
public function TwitterData($access_token = false)
{
require_once ROOTPATH . "data/third_party/twitteroauth/src/TwitterOAuth.php";
$connection = new TwitterOAuth($this->twitter_config['ckey'], $this->twitter_config['csecret'], $access_token['oauth_token'], $access_token['oauth_token_secret']);
$data = $connection->get("account/verify_credentials", array("include_email" => 'true'));
$this->SaveUser('twitter:' . $data->screen_name, 2, json_encode($access_token), json_encode($data));
}
示例11: getMe
/**
* Return info about login user
* @param $oauthToken
* @param $oauthVerifier
* @return \API|mixed
* @throws Exception
*/
public function getMe($oauthToken, $oauthVerifier)
{
$sessionSection = $this->session->getSection("twitter");
if ($oauthToken != "" && $sessionSection->oauth_token !== $oauthToken) {
//$sessionSection->oauth_status = 'oldtoken';
throw new Exception("Twitter token is old. Try again login");
}
//Create TwitteroAuth object with app key/secret and token key/secret from default phase
$this->twitterOAuth = new \TwitterOAuth($this->params["consumerKey"], $this->params["consumerSecret"], $sessionSection->oauth_token, $sessionSection->oauth_token_secret);
//Request access tokens from twitter
$access_token = $this->twitterOAuth->getAccessToken($oauthVerifier);
//Save the access tokens
$sessionSection->access_token = $access_token;
// Remove no longer needed request tokens
unset($sessionSection->oauth_token);
unset($sessionSection->oauth_token_secret);
if (200 != $this->twitterOAuth->http_code) {
//Save HTTP status for error dialog on connnect page.
throw new Exception("Twitter login. Something is wrong");
}
//The user has been verified
//$sessionSection->status = 'verified';
$user_info = $this->twitterOAuth->get('account/verify_credentials');
$this->setSocialLoginCookie(self::SOCIAL_NAME);
return $user_info;
}
示例12: getList
public static function getList(&$params)
{
$list = array();
if (!class_exists('TwitterOAuth')) {
require_once dirname(__FILE__) . '/twitteroauth.php';
}
$consumerKey = trim($params->get('consumekey'));
$consumerSecret = trim($params->get('consumersecret'));
$oAuthToken = trim($params->get('access_token'));
$oAuthSecret = trim($params->get('access_token_secret'));
$screenName = $params->get('screenname');
$notweets = $params->get('count', 6);
if (!$consumerKey || !$consumerSecret || !$screenName) {
return;
}
$_time = time();
$Tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
$tweets = $Tweet->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $screenName . "&count=" . $notweets);
$items = json_decode($tweets);
if (empty($items) || isset($items->errors)) {
return;
}
foreach ($items as $item) {
$text = preg_replace('@(https?://([-\\w\\.]+)+(/([\\w/_\\.]*(\\?\\S+)?(#\\S+)?)?)?)@', '<a target="_blank" href="$1">$1</a>', $item->text);
$text = preg_replace('/@(\\w+)/', '<a target="_blank" href="http://twitter.com/$1">@$1</a>', $text);
$text = preg_replace('/(?:^|\\s)+#(\\w+)/', ' <a target="_blank" href="http://search.twitter.com/search?q=%23$1">#$1</a>', $text);
$item->_text = $text;
$item->_full_name = $item->user->name;
$item->_username = '@' . $item->user->screen_name;
$item->_twitter_link = 'http://www.twitter.com/' . $item->user->screen_name;
$item->_image = $item->user->profile_image_url;
$list[] = $item;
}
return $list;
}
示例13: getContent
public function getContent()
{
try {
$dataKey = self::CONTENT;
$content = $this->getData($dataKey);
if ($content === false) {
require_once 'Twitter/twitteroauth.php';
$consumer_key = $this->config->getTwitterConsummerKey();
$consumer_secret = $this->config->getTwitterConsummerSecret();
$oauth_token = $this->config->getTwitterAuthToken();
$oauth_token_secret = $this->config->getTwitterAuthTokenSecret();
/* Create a TwitterOauth object with consumer/user tokens. */
$connection = new \TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
$user = "Cherbouquin";
/* Nom d'utilisateur sur Twitter */
$count = 10;
/* Nombre de message à afficher */
$query = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=' . $user . '&count=' . $count;
// Your Twitter API query
$content = $connection->get($query);
$this->setData($dataKey, $content);
}
return $content;
} catch (\Exception $exc) {
$this->logException(get_class(), __FUNCTION__, $exc);
}
}
示例14: IOAgetTweets
/**
* Twitter Shortcode using aouth
*/
function IOAgetTweets($count = 20, $username = false, $ioa_options = false)
{
global $super_options;
require_once HPATH . '/lib/twitteroauth/twitteroauth.php';
$settings = array('oauth_access_token' => $super_options[SN . '_twitter_token'], 'oauth_access_token_secret' => $super_options[SN . '_twitter_secret_token'], 'consumer_key' => $super_options[SN . '_twitter_key'], 'consumer_secret' => $super_options[SN . '_twitter_secret_key']);
$data = array();
if (get_transient(SN . '_ioa_tweets')) {
$data = get_transient(SN . '_ioa_tweets');
} else {
$connection = new TwitterOAuth($super_options[SN . '_twitter_key'], $super_options[SN . '_twitter_secret_key'], $super_options[SN . '_twitter_token'], $super_options[SN . '_twitter_secret_token']);
$data = $connection->get('statuses/user_timeline');
set_transient(SN . '_ioa_tweets', $data, 60 * 60 * 3);
}
$i = 0;
$filter_array = array();
if (!isset($data->errors)) {
foreach ($data as $d) {
if ($i > $count) {
break;
}
$filter_array[] = array("text" => $d->text);
$i++;
}
}
return $filter_array;
}
示例15: getProfile
public function getProfile()
{
$twitter = new TwitterOAuth(LeapTwitter::API_KEY, LeapTwitter::API_SECRET, LeapTwitter::ACCESS_TOKEN, LeapTwitter::ACCESS_TOKEN_SECRET);
$url = LeapTwitter::TWITTER_TIMELINE . "screen_name=" . LeapTwitter::TWITTER_DISPLAY_NAME . "&count=" . LeapTwitter::TWITTER_COUNT;
$urlImg = LeapTwitter::TWITTER_IMG . "screen_name=" . LeapTwitter::TWITTER_DISPLAY_NAME;
return json_encode($twitter->get($urlImg));
}