/** * wpt Latest Tweets widget class. */ function wpt_get_user($twitter_ID = false) { if (!$twitter_ID) { return; } $options = array('screen_name' => $twitter_ID); $key = get_option('app_consumer_key'); $secret = get_option('app_consumer_secret'); $token = get_option('oauth_token'); $token_secret = get_option('oauth_token_secret'); $connection = new jd_TwitterOAuth($key, $secret, $token, $token_secret); $result = $connection->get("https://api.twitter.com/1.1/users/show.json?screen_name={$twitter_ID}", $options); return json_decode($result); }
private function oauthGetTweets($screenname, $options) { $key = $this->defaults['key']; $secret = $this->defaults['secret']; $token = $this->defaults['token']; $token_secret = $this->defaults['token_secret']; $cachename = $screenname . "-" . $this->getOptionsHash($options); $options = array_merge($options, array('screen_name' => $screenname, 'count' => 20)); if (empty($key)) { return array('error' => 'Missing Consumer Key - Check Settings'); } if (empty($secret)) { return array('error' => 'Missing Consumer Secret - Check Settings'); } if (empty($token)) { return array('error' => 'Missing Access Token - Check Settings'); } if (empty($token_secret)) { return array('error' => 'Missing Access Token Secret - Check Settings'); } if (empty($screenname)) { return array('error' => 'Missing Twitter Feed Screen Name - Check Settings'); } $connection = new jd_TwitterOAuth($key, $secret, $token, $token_secret); $result = $connection->get('https://api.twitter.com/1.1/statuses/user_timeline.json', $options); $result = json_decode($result); if (is_file($this->getCacheLocation())) { $cache = json_decode(file_get_contents($this->getCacheLocation()), true); } if (!isset($result->error)) { $cache[$cachename]['time'] = time(); $cache[$cachename]['tweets'] = $result; $file = $this->getCacheLocation(); $this->save_cache($file, json_encode($cache)); } else { if (is_array($results) && isset($result['errors'][0]) && isset($result['errors'][0]['message'])) { $last_error = '[' . date('r') . '] Twitter error: ' . $result['errors'][0]['message']; $this->st_last_error = $last_error; } else { $last_error = '[' . date('r') . ']' . __('Twitter returned an invalid response. It is probably down.', 'wp-to-twitter'); $this->st_last_error = $last_error; } } return $result; }
private function oauthGetTweets($screenname, $options) { $key = $this->defaults['key']; $secret = $this->defaults['secret']; $token = $this->defaults['token']; $token_secret = $this->defaults['token_secret']; $cachename = $screenname . "-" . $this->getOptionsHash($options); $options = array_merge($options, array('screen_name' => $screenname, 'count' => 20)); if (empty($key)) { return array('error' => 'Missing Consumer Key - Check Settings'); } if (empty($secret)) { return array('error' => 'Missing Consumer Secret - Check Settings'); } if (empty($token)) { return array('error' => 'Missing Access Token - Check Settings'); } if (empty($token_secret)) { return array('error' => 'Missing Access Token Secret - Check Settings'); } if (empty($screenname)) { return array('error' => __('Missing Twitter Feed Screen Name - Check Settings', 'wp-to-twitter')); } $connection = new jd_TwitterOAuth($key, $secret, $token, $token_secret); if (isset($options['search'])) { $args = array('q' => urlencode($options['search']), 'result_type' => urlencode($options['result_type'])); if ($options['geocode'] != '') { $args['geocode'] = urlencode($options['geocode']); } $url = add_query_arg($args, 'https://api.twitter.com/1.1/search/tweets.json'); $result = $connection->get($url, $options); } else { $result = $connection->get('https://api.twitter.com/1.1/statuses/user_timeline.json', $options); } $result = json_decode($result); if (isset($options['search'])) { if (!method_exists($result, 'errors')) { $result = $result->statuses; } else { $errors = $result->errors; $return = ''; foreach ($errors as $error) { $return .= "<li>{$error->message}</li>"; } echo "<ul>" . $return . "</ul>"; return; } } if (is_file($this->getCacheLocation())) { $cache = json_decode(file_get_contents($this->getCacheLocation()), true); } if (!isset($result->error)) { $cache[$cachename]['time'] = time(); $cache[$cachename]['tweets'] = $result; $file = $this->getCacheLocation(); $this->save_cache($file, json_encode($cache)); } else { if (is_array($result) && isset($result['errors'][0]) && isset($result['errors'][0]['message'])) { $last_error = '[' . date('r') . '] ' . sprintf(__('Twitter error: %s', 'wp-to-twitter'), $result['errors'][0]['message']); $this->st_last_error = $last_error; } else { $last_error = '[' . date('r') . ']' . __('Twitter returned an invalid response. It is probably down.', 'wp-to-twitter'); $this->st_last_error = $last_error; } } // Run an action on the results output from the Twitter widget query do_action('wpt_process_tweets', $result, $screenname, $options); return $result; }