function broadcast_oauth($notice, Foreign_link $flink) { try { $user = $flink->getUser(); } catch (ServerException $e) { common_log(LOG_WARNING, 'Discarding broadcast_oauth for notice ' . $notice->id . ' because of exception: ' . $e->getMessage()); return true; } $statustxt = format_status($notice); $params = twitter_update_params($notice); $token = TwitterOAuthClient::unpackToken($flink->credentials); $client = new TwitterOAuthClient($token->key, $token->secret); $status = null; try { $status = $client->statusesUpdate($statustxt, $params); if (!empty($status)) { Notice_to_status::saveNew($notice->id, twitter_id($status)); } } catch (OAuthClientException $e) { return process_error($e, $flink, $notice); } if (empty($status)) { // This could represent a failure posting, // or the Twitter API might just be behaving flakey. $errmsg = sprintf('Twitter bridge - No data returned by Twitter API when ' . 'trying to post notice %d for User %s (user id %d).', $notice->id, $user->nickname, $user->id); common_log(LOG_WARNING, $errmsg); return false; } // Notice crossed the great divide $msg = sprintf('Twitter bridge - posted notice %d to Twitter using ' . 'OAuth for User %s (user id %d).', $notice->id, $user->nickname, $user->id); common_log(LOG_INFO, $msg); return true; }