We prove uniqueness of $g$-measures for $g$-functions satisfying quadratic summability of variations. Our result is in contrast to the situation of, \eg, the one-dimensional Ising model with long-range interactions, since $\ell_1$-summability of variations is required for general potentials. We illustrate this difference with some examples. To prove our main result we use a product martingale argument. We also give conditions for uniqueness of general $G$-measures, \ie, the case for general potentials, based on our investigation of the probabilistic case involving $g$-functions.