In according with Landau's Mechanics the number of independent integrals of motion for a closed mechanical system with $s$ degrees of freedom is $2s-1$. We can express the $2s-1$ arbitrary constants $C_1,C_2,...,C_{2s-1}$ as functions of $q$ and $\dot{q}$, and these functions will be integrals of the motion.
Thus for a mass with a spring we have only 1 integral (the energy), but I do not understand how to obtained it, indeed for $m\ddot{x}+kx=0$ I can write: $x=A\cos{\omega t}+B\sin{\omega t}$ and $\dot{x}=-A\omega \sin{\omega t}+B\omega\cos{\omega t}$. How can I express $A=f_1(q,\dot{q})$ and $B=f_2(q,\dot{q})$ if, for istance, $A=x_0$ and $B=0$?
There is a similar question in What is the standard procedure to form the first integrals of a motion? but I don't understand the answer.