/**
  * Saves a Foreign_link between Twitter user and local user,
  * which includes the access token and secret.
  *
  * @param int        $user_id StatusNet user ID
  * @param int        $twuid   Twitter user ID
  * @param OAuthToken $token   the access token to save
  *
  * @return nothing
  */
 function saveForeignLink($user_id, $twuid, $access_token)
 {
     $flink = new Foreign_link();
     $flink->user_id = $user_id;
     $flink->service = TWITTER_SERVICE;
     // delete stale flink, if any
     $result = $flink->find(true);
     if (!empty($result)) {
         $flink->safeDelete();
     }
     $flink->user_id = $user_id;
     $flink->foreign_id = $twuid;
     $flink->service = TWITTER_SERVICE;
     $creds = TwitterOAuthClient::packToken($access_token);
     $flink->credentials = $creds;
     $flink->created = common_sql_now();
     // Defaults: noticesync on, everything else off
     $flink->set_flags(true, false, false, false);
     $flink_id = $flink->insert();
     if (empty($flink_id)) {
         common_log_db_error($flink, 'INSERT', __FILE__);
         // TRANS: Server error displayed when linking to a Twitter account fails.
         $this->serverError(_m('Could not link your Twitter account.'));
     }
     return $flink_id;
 }