The key difference between a library and a framework is "Inversion of Control".
When you call a method from a library, you are in control. But with a framework, the control is inverted: the framework calls you.
Both of them define an API for programmers to use. To put those together, we can think of a library as a certain function of an application, a framework as the skeleton of the application, and an API as a connector to put those together. A typical development process normally starts with a framework and fills out functions defined in libraries using the API.