Whell, i was gonna paste the code here,, but it was too long...
its now an attatchment... :/
Its not my code,, i got it from The API-Guide, (www.allapi.com) its free, and has a massive database of all the api calls you could ever think of... ALWAYs comes in handy