API is sort of a, not really, kind of like a library but it isn't all (lol).
Let's say that I create a program that allows you to upload pictures. I call this program PictureUploader.
Now, since everyone is using PictureUploader, I want to make is so that other programmers and can build software that can connect to PictureUploader and upload, download and manage photos through their own applications. In other words, I want them to use my service, but use their own applications. So parts of my application are able to be extended via an API. I determine what is in this API, what methods can be called and what properties can be read or set.
So I may create an interface like GetAllPhotos() which will return ALL of the links to the photos. Now when you are building your software and you want to use my API, one of the methods you can use to retrieve photos is GetAllPhotos().
Twitter does this
so that you can access Tweets from Twitter.
A library is something like