"I just want to apoligise for (whatever it was I did to upset) you in the last few days. I didn't realise X( or I misunderstood the situation, or whatever). I'm really sorry that my behaviour upset you, and I hope that you will accept my apologies.
I hope that this will not spoil our friendship and I look forward to seeing you again soon. "
I would suggest something like this - you don't want to go on too long or you start digging yourself into an even bigger hole!