public function fire($app, array $request) { // CodeBird Instance \Codebird\Codebird::setConsumerKey($this->getConfig('consumer_key'), $this->getConfig('consumer_secret')); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($this->getConfig('access_token'), $this->getConfig('access_token_secret')); $cb->setReturnFormat(CODEBIRD_RETURNFORMAT_JSON); // Set Values $username = $this->getConfig('username'); $count = $this->getConfig('count'); // Get timeline return $cb->statuses_userTimeline("screen_name={$username}&count={$count}&exclude_replies=true"); }
public function __construct() { \Codebird\Codebird::setConsumerKey('API-KEY', 'API-SECRET'); // static, see 'Using multiple Codebird instances' $this->cb = \Codebird\Codebird::getInstance(); if (!isset($_SESSION['oauth_token'])) { $reply = $this->cb->oauth_requestToken(array('oauth_callback' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])); $this->cb->setToken($reply->oauth_token, $reply->oauth_token_secret); $_SESSION['oauth_token'] = $reply->oauth_token; $_SESSION['oauth_token_secret'] = $reply->oauth_token_secret; $_SESSION['oauth_verify'] = true; $auth_url = $this->cb->oauth_authorize(); header('Location: ' . $auth_url); die; } elseif (isset($_GET['oauth_verifier']) && isset($_SESSION['oauth_verify'])) { $this->cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); unset($_SESSION['oauth_verify']); $reply = $this->cb->oauth_accessToken(array('oauth_verifier' => $_GET['oauth_verifier'])); $_SESSION['oauth_token'] = $reply->oauth_token; $_SESSION['oauth_token_secret'] = $reply->oauth_token_secret; header('Location: ' . 'index.php'); die; } $this->cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); }
/** * Register the service provider. * * @return void */ public function register() { $this->app->bind(\Codebird\Codebird::class, function ($app) { \Codebird\Codebird::setConsumerKey(config('birdy.CONSUMER_KEY'), config('birdy.CONSUMER_SECRET')); return \Codebird\Codebird::getInstance(); }); }
/** * Gets most recent tweets * @param String twitter username (ex. kevindeleon) * @param String number of tweets * @param String include retweets true, false * @return JSON encoded tweets */ public static function get_most_recent($screen_name, $count, $retweets = NULL) { //let's include codebird, as it's going to be doing the oauth lifting for us require_once 'codebird.php'; //These are your keys/tokens/secrets provided by Twitter $CONSUMER_KEY = '<YOUR KEY>'; $CONSUMER_SECRET = '<YOUR SECRET>'; $ACCESS_TOKEN = '<YOUR TOKEN>'; $ACCESS_TOKEN_SECRET = '<YOUR TOKEN SECRET>'; //Get authenticated \Codebird\Codebird::setConsumerKey($CONSUMER_KEY, $CONSUMER_SECRET); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($ACCESS_TOKEN, $ACCESS_TOKEN_SECRET); //These are our params passed in $params = array('screen_name' => $screen_name, 'count' => $count, 'include_rts' => $retweets); //tweets returned by Twitter $tweets = (array) $cb->statuses_userTimeline($params); //Let's encode it for our JS/jQuery return json_encode($tweets); }
public function __construct($consumer_key = null, $consumer_secret = null, $count_messages = 20, $count_timeline = 40) { $this->count_messages = $count_messages; $this->count_timeline = $count_timeline; Codebird::setConsumerKey($consumer_key, $consumer_secret); $this->cb = Codebird::getInstance(); if (isset($_GET['oauth_verifier']) && isset($_SESSION['twitter_verify'])) { $this->cb->setToken($_SESSION['twitter']['oauth_token'], $_SESSION['twitter']['oauth_token_secret']); unset($_SESSION['twitter_verify']); $reply = $this->cb->oauth_accessToken(['oauth_verifier' => $_GET['oauth_verifier']]); $twitterOauth = TwitterClientOauth::where('user_id', $_SESSION['user_id'])->first(); if ($twitterOauth) { $twitterOauth->update(['user_id' => $_SESSION['user_id'], 'oauth_token' => $reply->oauth_token, 'oauth_token_secret' => $reply->oauth_token_secret, 'screen_name' => $reply->screen_name, 'oauth_verifier' => true]); } else { TwitterClientOauth::create(['user_id' => $_SESSION['user_id'], 'oauth_token' => $reply->oauth_token, 'oauth_token_secret' => $reply->oauth_token_secret, 'screen_name' => $reply->screen_name, 'oauth_verifier' => true]); } $_SESSION['twitter']['oauth_token'] = $reply->oauth_token; $_SESSION['twitter']['oauth_token_secret'] = $reply->oauth_token_secret; $_SESSION['twitter']['screen_name'] = $reply->screen_name; $_SESSION['twitter']['twitterOauth'] = true; } if (isset($_SESSION['twitter'])) { $this->cb->setToken($_SESSION['twitter']['oauth_token'], $_SESSION['twitter']['oauth_token_secret']); } }
function ViewList() { $params = array('screen_name' => $_SESSION['me']['tw_screen_name']); \Codebird\Codebird::setConsumerKey(CONSUMER_KEY, CONSUMER_SECRET); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($_SESSION['me']['tw_access_token'], $_SESSION['me']['tw_access_token_secret']); $userShow = $cb->users_show($params); $strList = "<ui>"; $strList = $strList . "<div onclick=\"obj=document.getElementById('menu').style; obj.display=(obj.display=='none')?'block':'none';\">"; $strList = $strList . "<a style=\"cursor:pointer;\">"; $strList = $strList . "<img alt=\"" . $userShow->screen_name . "\" src=\"" . $userShow->profile_image_url_https . "\" >"; $strList = $strList . "</a>"; $strList = $strList . "</div>"; $params = array('user_id' => $_SESSION['me']['tw_user_id']); $user = $cb->friends_ids($params); $strList = $strList . "<li>"; foreach ($user->ids as $id) { $params = array('user_id' => $id); $userFriend = $cb->users_show($params); $strList = $strList . "<div id=\"user_icon\">"; $strList = $strList . "<form action=\"userview.php\" target=\"_blank\" method=\"POST\">"; $strList = $strList . "<input type=\"image\" alt=\"" . $userFriend->screen_name . "\" src=\"" . $userFriend->profile_image_url_https . "\" "; $strList = $strList . "name=\"" . $userFriend->screen_name . "\" "; $strList = $strList . ">"; $strList = $strList . "</form>"; $strList = $strList . "</div>"; } $strList = $strList . "</li>"; $strList = $strList . "</ul>"; echo $strList; }
/** * Initialize login plugin if path matches. */ public function initialize() { /** @var Uri $uri */ $uri = $this->grav['uri']; // Autoload classes $autoload = __DIR__ . '/vendor/autoload.php'; if (!is_file($autoload)) { throw new \Exception('Login Plugin failed to load. Composer dependencies not met.'); } require_once $autoload; if ($uri->path() == "/twittercounter") { //AUTHORIZE TWITTER USING CODEBIRD \Codebird\Codebird::setConsumerKey("e1tnpPE0Yn21ihdmdiIkCoXwW", "HCjxxLTjaHYxvcO0PwS65Fy5deULMDYyts2Y63fi1IRGHSl8fc"); $this->codebird = \Codebird\Codebird::getInstance(); $authReply = $this->codebird->oauth2_token(); $bearer_token = $authReply->access_token; $this->codebird->setToken('3857076435-E8PgaMjUlOTOKZrgnILDSnhbFVyyerqRH5B2qyA', 'pwIDLs6FUuoISVFFh59YJcC78PF72ZZYZFaKF8njXdNMW'); //RUN COUNT $this->currentHashtag = 1; $first = $this->hashtagCounter(); $this->currentHashtag = 2; $second = $this->hashtagCounter(); $this->currentHashtag = 3; $third = $this->hashtagCounter(); $this->currentHashtag = 4; $fourth = $this->hashtagCounter(); $this->currentHashtag = 5; $fifth = $this->hashtagCounter(); echo json_encode(array('hashtags' => array($first, $second, $third, $fourth, $fifth))); //$this->displayStatuses(); exit; } }
function Send($params) { echo $_SERVER['DOCUMENT_ROOT']; require_once $_SERVER['DOCUMENT_ROOT'] . '/codebird/codebird.php'; try { $consumer_key = "iD1vnMw3VMn1ptYZx4JBWl895"; $consumer_secret = "CIR3jEUXXR5Yxi6K1j6HDdNsKNGXoECfARn8JasK0q09AN5WJm"; $access_token = "3111426681-HJXPz0Fz7Ofjd3GmBXx6tZyK9sGJBPTsmoKpKZW"; $access_secret = "vv23K574Re2x3p5QSZ29ugPyaNS7b3cB2CVTzlh15XHwq"; $cb; // Fetch new Twitter Instance $cb = \Codebird\Codebird::getInstance(); $cb->setConsumerKey($consumer_key, $consumer_secret); //\Codebird\Codebird::setConsumerKey($this->consumer_key, $this->consumer_secret); //$this->twitter = Codebird::getInstance(); // Set access token $cb->setToken($access_token, $access_secret); //$this->twitter->setToken($this->access_token, $this->access_secret); //$reply = $cb->statuses_update($params); $reply = $cb->statuses_updateWithMedia($params); } catch (Exception $ex) { echo $ex; file_put_contents('tmp/Log.txt', $ex->getMessage(), FILE_APPEND); } }
public static function user_timeline() { // Twitter OAuth library: https://github.com/mynetx/codebird-php require_once '../codebird.php'; // Twitter OAuth Settings: $CONSUMER_KEY = ''; $CONSUMER_SECRET = ''; $ACCESS_TOKEN = ''; $ACCESS_TOKEN_SECRET = ''; // Get authenticated: \Codebird\Codebird::setConsumerKey($CONSUMER_KEY, $CONSUMER_SECRET); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($ACCESS_TOKEN, $ACCESS_TOKEN_SECRET); // Retrieve posts: $username = strip_tags(trim($_GET['username'])); $count = strip_tags(trim($_GET['count'])); // API Settings: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline $params = array('screen_name' => $username, 'count' => $count); // Make the REST call: $data = (array) $cb->statuses_userTimeline($params); unset($data['httpstatus']); unset($data['rate']); foreach ($data as $tweet) { $tweets[] = array('username' => $tweet->user->screen_name, 'profile_image' => $tweet->user->profile_image_url, 'text' => $tweet->text, 'created' => $tweet->created_at); } // Output result in JSON: return json_encode($tweets); }
public static function hashtag() { // Twitter OAuth library: https://github.com/mynetx/codebird-php require_once '../codebird.php'; // Twitter OAuth Settings: $CONSUMER_KEY = ''; $CONSUMER_SECRET = ''; $ACCESS_TOKEN = ''; $ACCESS_TOKEN_SECRET = ''; // Get authenticated: \Codebird\Codebird::setConsumerKey($CONSUMER_KEY, $CONSUMER_SECRET); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($ACCESS_TOKEN, $ACCESS_TOKEN_SECRET); // Retrieve posts: $q = strip_tags(trim($_GET['q'])); $count = strip_tags(trim($_GET['count'])); // API Settings: https://dev.twitter.com/docs/api/1.1/get/search/tweets $params = array('q' => $q, 'count' => $count); // Make the REST call: $data = (array) $cb->search_tweets($params); unset($data['search_metadata']); unset($data['httpstatus']); unset($data['rate']); // Output result in JSON: return json_encode($data); }
private function postTweet($text) { Codebird::setConsumerKey($this->container->getParameter('twitter_consumer_key'), $this->container->getParameter('twitter_consumer_secret')); $cb = Codebird::getInstance(); $cb->setToken($this->container->getParameter('twitter_access_token'), $this->container->getParameter('twitter_access_token_secret')); $reply = $cb->statuses_update('status=' . $text); return $reply; }
/** * Overload magic __call() to transparently intercept Exceptions * * Most exceptions encountered in production are API timeouts - this will * transparently handle these Exceptions to prevent fatal errors */ public function __call($function, $arguments) { try { return parent::__call($function, $arguments); } catch (Exception $e) { return array(); } }
public function postTweet($status) { Codebird::setConsumerKey($this->container->getParameter('hm_twitterApiKey'), $this->container->getParameter('hm_twitterApiSecret')); $cb = Codebird::getInstance(); $cb->setToken($this->container->getParameter('hm_twitterApiToken'), $this->container->getParameter('hm_twitterApiTokenSecret')); $reply = $cb->statuses_update('status=' . $status); return $reply; }
public function __construct() { // Fetch new Twitter Instance Codebird::setConsumerKey($this->consumer_key, $this->consumer_secret); $this->twitter = Codebird::getInstance(); // Set access token $this->twitter->setToken($this->access_token, $this->access_secret); }
public function hashtag() { \Codebird\Codebird::setConsumerKey($this->_consumer_key, $this->_consumer_secret); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($this->_access_token, $this->_access_token_secret); $params = array('q' => isset($_GET['hashtag']) ? $_GET['hashtag'] : NULL, 'count' => isset($_GET['count']) ? $_GET['count'] : 10); $data = (array) $cb->search_tweets($params); return json_encode($data); }
/** * Returns an initialized Codebird instance. * @return mixed initialized Codebird instance */ function get_codebird_instance() { require_once 'codebird.php'; global $current_user; \Codebird\Codebird::setConsumerKey(get_option('status-twitter-oauth-consumer-key'), get_option('status-twitter-oauth-consumer-secret')); $cb = \Codebird\Codebird::getInstance(); $cb->setToken(get_user_meta($current_user->ID, 'oauth_token', true), get_user_meta($current_user->ID, 'oauth_token_secret', true)); return $cb; }
/** * @param $tweet * @param null $image * @return bool */ public function m_post($tweet, $image = null) { $status = ['status' => substr($tweet, 0, 140)]; if (!$image) { return $this->cb->statuses_update($status); } $status['media[]'] = $image; return $this->cb->statuses_updateWithMedia($status); }
public function __construct() { Codebird::setConsumerKey(env('TWITTER_CONSUMER_KEY'), env('TWITTER_CONSUMER_SECRET')); $this->citcuit = new CitcuitController(); $this->api = Codebird::getInstance(); $this->middleware(function ($request, $next) { $this->api->setToken(session('auth.oauth_token'), session('auth.oauth_token_secret')); return $next($request); }); }
/** * [twitter description] * @param [type] $_params array contain twitte params like status * @param [type] $_token array with 5 key * [ * ConsumerKey=>'', * ConsumerSecret=>'', * AccessToken=>'', * AccessTokenSecret=>'', * status=>'' * ] * @return [type] return status of twitte */ public static function twitter($_params, $_token = null) { require addons . 'lib/SocialNetwork/codebird/codebird.php'; if (is_array($_token) && count($_token) === 5) { // use the input array } else { // get token value from database if exist $qry = new \lib\dbconnection(); $qry = $qry->query('Select `option_key`, `option_value` from options where `option_cat` = "twitter"'); if ($qry->num() < 5) { return 'token'; } foreach ($qry->allassoc() as $key => $value) { $_token[$value['option_key']] = $value['option_value']; } // if twitter status is disable return false if (!isset($_token['status'])) { return 'disable'; } if ($_token['status'] !== 'enable') { return 'disable'; } } try { \Codebird\Codebird::setConsumerKey($_token['ConsumerKey'], $_token['ConsumerSecret']); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($_token['AccessToken'], $_token['AccessTokenSecret']); if (is_array($_params)) { // user passed params as twitter parameter like below lines // https://github.com/jublonet/codebird-php // $params = // [ // 'status' => 'I love London', // 'lat' => 51.5033, // 'long' => 0.1197, // 'media_ids' => $media_ids // ]; } else { $_params = array('status' => $_params); } $reply = array(); $reply['callback'] = $cb->statuses_update($_params); $reply['status'] = $reply['callback']->httpstatus; // return $reply; } catch (\Exception $e) { $reply['callback'] = $e->getMessage(); $reply['status'] = 'fail'; // var_dump('Caught exception: ', $e->getMessage(), "\n"); // return $e->getMessage(); } finally { $reply['date'] = date('Y-m-d H:i:s'); return $reply; } }
public function __construct() { $this->config = Zend_Registry::get('config'); \Codebird\Codebird::setConsumerKey($this->config->twitter->consumerKey, $this->config->twitter->consumerSecret); $this->cb = \Codebird\Codebird::getInstance(); if (isset($this->config->twitter->bearerToken)) { $bearerToken = $this->config->twitter->bearerToken; } else { $bearerToken = $this->_fetchBearerToken(); } \Codebird\Codebird::setBearerToken($bearerToken); }
function __construct($consumerKey, $consumerValue, $tokenKey, $tokenValue, $botName) { $this->consumerKey = $consumerKey; $this->consumerValue = $consumerValue; $this->tokenKey = $tokenKey; $this->tokenValue = $tokenValue; $this->botName = $botName; $this->percentageThreshold = ""; echo "In construct "; \Codebird\Codebird::setConsumerKey($this->consumerKey, $this->consumerValue); // static, see 'Using multiple Codebird instances' $this->cb = \Codebird\Codebird::getInstance(); $this->cb->setToken($this->tokenKey, $this->tokenValue); $results = $this->cb->statuses_mentionsTimeline(array("screen_name" => $this->botName, "count" => 5000)); //print_r($results); $reply_tweet_id = array(); $reply_tweet_time = array(); foreach ($results as $question) { echo "<h1>" . $question->user->screen_name . "\\ " . $question->in_reply_to_screen_name . "</h1><br>"; if ($question->user->screen_name != '' && $question->in_reply_to_screen_name != '') { // echo $question->user->screen_name . ": User Screenname<br/>"; // echo $question->user->id . ": User id<br/>"; // echo $question->text . " : USER tweet <br/>"; // echo $question->id_str . " : TWEET ID"; $reply_tweet_id[] = $question->id_str; $reply_tweet_username[] = $question->user->screen_name; $reply_tweet_time[] = $question->created_at; } // $output[]=$question->user->screen_name; } //Checking for API limits. It happens. if ($DEBUGME == 1) { echo $results->rate['limit'] . " limit<br>"; echo $results->rate['remaining'] . " remaining<br>"; echo $results->rate['reset'] . " TIME<br>"; } print_r($reply_tweet_id); echo "<br>"; print_r($reply_tweet_username); echo "<br>"; $this->userToTweet = $reply_tweet_username[0]; $this->replyToTweetID = $reply_tweet_id[0]; }
function user_oauth() { //require_once ('codebird.php'); $cb = \Codebird\Codebird::getInstance(); // Flag forces twitter_process() to use OAuth signing // $GLOBALS['user']['type'] = 'oauth'; // If there's no OAuth Token, take the user to Twiter's sign in page if (!isset($_SESSION['oauth_token'])) { // get the request token $reply = $cb->oauth_requestToken(array('oauth_callback' => SERVER_NAME . $_SERVER['REQUEST_URI'])); // store the token $cb->setToken($reply->oauth_token, $reply->oauth_token_secret); $_SESSION['oauth_token'] = $reply->oauth_token; $_SESSION['oauth_token_secret'] = $reply->oauth_token_secret; $_SESSION['oauth_verify'] = true; // redirect to auth website $auth_url = $cb->oauth_authorize(); header('Location: ' . $auth_url); die; } elseif (isset($_GET['oauth_verifier']) && isset($_SESSION['oauth_verify'])) { // verify the token $cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); unset($_SESSION['oauth_verify']); // get the access token $reply = $cb->oauth_accessToken(array('oauth_verifier' => $_GET['oauth_verifier'])); // store the token (which is different from the request token!) $_SESSION['oauth_token'] = $reply->oauth_token; $_SESSION['oauth_token_secret'] = $reply->oauth_token_secret; $cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); // Verify and get the username $user = $cb->account_verifyCredentials(); $GLOBALS['user']['username'] = $user->screen_name; // Store ACCESS tokens in COOKIE $GLOBALS['user']['password'] = $_SESSION['oauth_token'] . '|' . $_SESSION['oauth_token_secret']; _user_save_cookie(1); // send to same URL, without oauth GET parameters header('Location: ' . BASE_URL); die; } header('Location: ' . BASE_URL); }
/** * Gets most recent tweets * @param String twitter username (ex. kevindeleon) * @param String number of tweets * @param String include retweets true, false * @return JSON encoded tweets */ public static function get_most_recent($screen_name, $count, $retweets = NULL) { //let's include codebird, as it's going to be doing the oauth lifting for us require_once 'codebird.php'; //These are your keys/tokens/secrets provided by Twitter // dev.twitter.com -> create an app -> request oauth token. Then look at the oAuth tab. $CONSUMER_KEY = '3soJowYY3RvGLyhg4xpoJA'; $CONSUMER_SECRET = 'ihH6rRYbNB3UszzhDdTKSVez3HCf67KDG0ufE69Oqw'; $ACCESS_TOKEN = '337592867-PbwVrwFziRbjQvQEFtFpBDmmZs5xt1C1V2fghn8A'; $ACCESS_TOKEN_SECRET = 'dNt44s1rmu8jh3bfmiyefsJkIIKHUKRYr33Jfx4YdM'; //Get authenticated \Codebird\Codebird::setConsumerKey($CONSUMER_KEY, $CONSUMER_SECRET); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($ACCESS_TOKEN, $ACCESS_TOKEN_SECRET); //These are our params passed in $params = array('screen_name' => $screen_name, 'count' => $count, 'rts' => $retweets); //tweets returned by Twitter //$tweets = (array) $cb->statuses_userTimeline($params); $tweets = (array) $cb->statuses_homeTimeline($params); //Let's encode it for our JS/jQuery return json_encode($tweets); }
/** * Fetch trends from Twitter based on Global and USA scopes. * * @return array */ private function twitter() { if (!($result = \Cache::get('twitter'))) { Codebird::setConsumerKey(env('TWITTER_KEY'), env('TWITTER_SECRET')); $codeBird = Codebird::getInstance(); $codeBird->setToken(env('TWITTER_TOKEN'), env('TWITTER_TOKEN_SECRET')); $usa = (array) $codeBird->trends_place('id=23424977'); $world = (array) $codeBird->trends_place('id=1'); if (@$usa[0] && @$world[0]) { \Cache::put('twitter', array_merge(array_map(function ($item) { $item->type = 'usa'; return $item; }, $usa[0]->trends), array_map(function ($item) { $item->type = 'world'; return $item; }, $world[0]->trends)), Carbon::now()->addMinutes(10)); $result = \Cache::get('twitter'); } else { $result = array(); } } return $result; }
<?php // DEPENDENCIES //////////////////////////////////////////////////////// require 'vendor/autoload.php'; require 'classes/baseapimodel.class.php'; require 'config.php'; //////////////////////////////////////////////////////////////////////// session_start(); // let's do it // twitter \Codebird\Codebird::setConsumerKey(TWITTER_API_KEY, TWITTER_API_SECRET); // static, see 'Using multiple Codebird instances' $oTwitter = \Codebird\Codebird::getInstance();
/** * Creates Codebird instance * * @return Codebird */ public function connect() { Codebird::setConsumerKey($this->credentials['consumer_key'], $this->credentials['consumer_secret']); return Codebird::getInstance(); }
function verify_twitter_credentials($twitter) { require_once OTHERS . "twitter/codebird.php"; \Codebird\Codebird::setConsumerKey($twitter['consumer_key'], $twitter['consumer_secret']); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($twitter['access_token'], $twitter['access_token_secret']); $reply = $cb->oauth2_token(); if (isset($reply->errors)) { return array('result' => false, 'message' => $reply->errors[0]->message); } else { return array('result' => true, 'message' => "Verifying credentials successful!"); } }
public function testCodebird() { $twitter = $this->setup(); $consumerKey = Config::inst()->get('SSTwitter', 'CONSUMER_KEY'); $consumerSecret = Config::inst()->get('SSTwitter', 'CONSUMER_SECRET'); $this->accessToken = Config::inst()->get('SSTwitter', 'OAUTH_TOKEN'); $this->accessSecret = Config::inst()->get('SSTwitter', 'OAUTH_SECRET'); TwitterObjectTest::setConsumerKey($consumerKey, $consumerSecret); $this->assertEquals(TwitterObjectTest::getConsumerKey(), $consumerKey); $this->assertEquals(TwitterObjectTest::getConsumerSecret(), $consumerSecret); $this->cb = \Codebird\Codebird::getInstance(); $this->cb->setToken($this->accessToken, $this->accessSecret); $this->assertEquals(TwitterObjectTest::getAccessToken(), $this->accessToken); $this->assertEquals(TwitterObjectTest::getAccessSecret(), $this->accessSecret); }
public static function processMessage($msg) { $params = json_decode($msg->body); print_r($params); try { $news = News::findOne($params->news_id); $text = mb_substr($news->title, 0, 140 - strlen(Yii::$app->params['domainName'] . $news->getLink()), 'utf-8'); $text .= " " . Yii::$app->params['domainName'] . $news->getLink(); Codebird::setConsumerKey(Yii::$app->params['twitter']['consumer_key'], Yii::$app->params['twitter']['consumer_secret']); $cb = Codebird::getInstance(); $cb->setToken(Yii::$app->params['twitter']['access_token'], Yii::$app->params['twitter']['access_token_secret']); $params = array('status' => $text, 'media[]' => $params->src); $reply = $cb->statuses_updateWithMedia($params); } catch (Exception $e) { echo $e->getMessage(); } $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); }
public function pollAction($id) { $site = $this->getDoctrine()->getRepository('StuartHashtagBundle:Site')->find($id); Codebird::setConsumerKey('WQOK7uxRI60gsCTsHnAMw', 'wPlLms2qIeqUBCcdFo2vAOWCcPMUm3hzmgI43EzMs'); // static, see 'Using multiple Codebird instances' $cb = Codebird::getInstance(); $reply = $cb->oauth2_token(); $bearer_token = $reply->access_token; $reply = $cb->search_tweets('q=' . $site->getHashtag() . '&include_en&rpp=20&show_user=true&include_entities=true&with_twitter_user_id=true&result_type=recent', true); $response = array('name' => $site->getName(), 'hashtag' => $site->getHashtag(), 'reply' => $reply); return new JsonResponse($response); }