Exemple #1
0
function broadcast_basicauth($notice, $flink)
{
    $user = $flink->getUser();
    $statustxt = format_status($notice);
    $params = twitter_update_params($notice);
    $client = new TwitterBasicAuthClient($flink);
    $status = null;
    try {
        $status = $client->statusesUpdate($statustxt, $params);
    } catch (BasicAuthException $e) {
        return process_error($e, $flink, $notice);
    }
    if (empty($status)) {
        $errmsg = sprintf('Twitter bridge - No data returned by Twitter API when ' . 'trying to post notice %d for %s (user id %d).', $notice->id, $user->nickname, $user->id);
        common_log(LOG_WARNING, $errmsg);
        $errmsg = sprintf('No data returned by Twitter API when ' . 'trying to post notice %d for %s (user id %d).', $notice->id, $user->nickname, $user->id);
        common_log(LOG_WARNING, $errmsg);
        return false;
    }
    $msg = sprintf('Twitter bridge - posted notice %d to Twitter using ' . 'HTTP basic auth for User %s (user id %d).', $notice->id, $user->nickname, $user->id);
    common_log(LOG_INFO, $msg);
    return true;
}
 function getTimeline($flink)
 {
     if (empty($flink)) {
         common_log(LOG_WARNING, $this->name() . " - Can't retrieve Foreign_link for foreign ID {$fid}");
         return;
     }
     common_debug($this->name() . ' - Trying to get timeline for Twitter user ' . $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.
     $client = null;
     if (TwitterOAuthClient::isPackedToken($flink->credentials)) {
         $token = TwitterOAuthClient::unpackToken($flink->credentials);
         $client = new TwitterOAuthClient($token->key, $token->secret);
         common_debug($this->name() . ' - Grabbing friends timeline with OAuth.');
     } else {
         $client = new TwitterBasicAuthClient($flink);
         common_debug($this->name() . ' - Grabbing friends timeline with basic auth.');
     }
     $timeline = null;
     try {
         $timeline = $client->statusesFriendsTimeline();
     } catch (Exception $e) {
         common_log(LOG_WARNING, $this->name() . ' - Twitter client unable to get friends timeline for user ' . $flink->user_id . ' - code: ' . $e->getCode() . 'msg: ' . $e->getMessage());
     }
     if (empty($timeline)) {
         common_log(LOG_WARNING, $this->name() . " - Empty timeline.");
         return;
     }
     common_debug(LOG_INFO, $this->name() . ' - Retrieved ' . sizeof($timeline) . ' statuses from Twitter.');
     // Reverse to preserve order
     foreach (array_reverse($timeline) as $status) {
         // Hacktastic: filter out stuff coming from this StatusNet
         $source = mb_strtolower(common_config('integration', 'source'));
         if (preg_match("/{$source}/", mb_strtolower($status->source))) {
             common_debug($this->name() . ' - 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();
 }