Example #1
0
 /**
  * Verifies a username and password against Twitter's API
  *
  * @param string $screen_name Twitter user name
  * @param string $password    Twitter password
  *
  * @return boolean success flag
  */
 function verifyCredentials($screen_name, $password)
 {
     $uri = 'http://twitter.com/account/verify_credentials.json';
     $data = get_twitter_data($uri, $screen_name, $password);
     if (!$data) {
         return false;
     }
     $user = json_decode($data);
     if (!$user) {
         return false;
     }
     $twitter_id = $user->id;
     if ($twitter_id) {
         return $twitter_id;
     }
     return false;
 }
Example #2
0
function retreive_twitter_friends($twitter_id, $screen_name, $password)
{
    $uri = "http://twitter.com/statuses/friends/{$twitter_id}.json?page=";
    $twitter_user = twitter_user_info($screen_name, $password);
    // Calculate how many pages to get...
    $pages = ceil($twitter_user->friends_count / 100);
    if ($pages == 0) {
        common_debug("Twitter bridge - Twitter user {$screen_name} has no friends! Lame.");
    }
    $friends = array();
    for ($i = 1; $i <= $pages; $i++) {
        $data = get_twitter_data($uri . $i, $screen_name, $password);
        if (!$data) {
            return null;
        }
        $more_friends = json_decode($data);
        if (!$more_friends) {
            return null;
        }
        $friends = array_merge($friends, $more_friends);
    }
    return $friends;
}
Example #3
0
 function getTimeline($flink)
 {
     if (empty($flink)) {
         common_log(LOG_WARNING, "Can't retrieve Foreign_link for foreign ID {$fid}");
         return;
     }
     $fuser = $flink->getForeignUser();
     if (empty($fuser)) {
         common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id);
         return;
     }
     if (defined('SCRIPT_DEBUG')) {
         common_debug('Trying to get timeline for Twitter user ' . "{$fuser->nickname} ({$flink->foreign_id}).");
     }
     // XXX: Biggest remaining issue - How do we know at which status
     // to start importing?  How many statuses?  Right now I'm going
     // with the default last 20.
     $url = 'http://twitter.com/statuses/friends_timeline.json';
     $timeline_json = get_twitter_data($url, $fuser->nickname, $flink->credentials);
     $timeline = json_decode($timeline_json);
     if (empty($timeline)) {
         common_log(LOG_WARNING, "Empty timeline.");
         return;
     }
     // Reverse to preserve order
     foreach (array_reverse($timeline) as $status) {
         // Hacktastic: filter out stuff coming from this Laconica
         $source = mb_strtolower(common_config('integration', 'source'));
         if (preg_match("/{$source}/", mb_strtolower($status->source))) {
             if (defined('SCRIPT_DEBUG')) {
                 common_debug('Skipping import of status ' . $status->id . ' with source ' . $source);
             }
             continue;
         }
         $this->saveStatus($status, $flink);
     }
     // Okay, record the time we synced with Twitter for posterity
     $flink->last_noticesync = common_sql_now();
     $flink->update();
 }