We study a refined version of Linnik's problem on the asymptotic behavior of the number of representations of integers m by an integral polynomial as m tends to infinity. Assuming that the polynomials arise from invariant theory, we reduce the question to the study of limiting behavior of measures invariant under unipotent flows. Our main tool is then Ratner's theorem on the uniform distribution of unipotent flows, in a form refined by Dani and Margulis [DM2]