You are here

function twitter_fetch_timeline in Twitter 6.2

Fetch the public timeline for a Twitter.com account.

Note that this function only requires a screen name, and not a password. As such, it can only retrieve statuses for publically visible Twitter accounts. Because it doesn't require authentication, it is also easier on the Twitter servers. Be kind, use this version whenever you can.

Parameters

$screen_name: The screen name of a Twitter.com user.

$filter_since: A boolean indicating that Twitter should only return statuses that have not been locally cached. This incurs an extra database hit, to retrieve the date of the most recent locally cached twitter message for the screen name.

$cache: A boolean indicating whether the statuses should be cached in the local site's database after they're retrieved.

Return value

An array of Twitter statuses.

See also

twitter_fetch_statuses()

2 calls to twitter_fetch_timeline()
twitter_cron in ./twitter.module
Implementation of hook_cron()
twitter_user_save in ./twitter.inc

File

./twitter.inc, line 82
A wrapper API for the Twitter microblogging service.

Code

function twitter_fetch_timeline($screen_name, $filter_since = TRUE, $cache = TRUE) {
  if ($filter_since) {
    $sql = "SELECT t.created_at FROM {twitter} t WHERE t.screen_name = '%s' ORDER BY t.created_at DESC";
    $since = db_result(db_query($sql, $screen_name));
  }
  $url = "http://" . variable_get('twitter_api_url', 'twitter.com') . "/statuses/user_timeline/{$screen_name}.xml";
  if (!empty($since)) {
    $url .= '?since=' . urlencode($since);
  }
  $results = drupal_http_request($url, array(), 'GET');
  if (_twitter_request_failure($results)) {
    return array();
  }
  else {
    $results = _twitter_convert_xml_to_array($results->data);
    if ($cache) {
      foreach ($results as $status) {
        twitter_cache_status($status);
      }
      twitter_touch_account($screen_name);
    }
    return $results;
  }
}