Temperature ($T_{eff}$) can be quite tricky to determine accurately as it interrelates to a number of other fundamental measurements.
Firstly, remember that the spectrum we observe from stars are pin-point, they give us the entire overall result and not a specific location or part of the star. We need to dissect the various parts to arrive at the fundamental parameters. We arrive at our results by iterating the values of the fundamental parameters until a model spectrum matches the true spectrum we observe. The issue is, like you say, the existence of a whole lot of uncertainties.
The first of these (although it doesn't have a large effect) is the Uncertainty Principle itself. This creates natural line broadening due to the emitted photon having a range of frequencies. The width of the line is determined by;
$$\Delta E \approx \frac{h}{T_{\text{decay}}}$$
where $\Delta E$ is the uncertainty in the energy,
$h$ is the Planck constant, and
$T_{\text{decay}}$ is the amount of time the electron stays in a high energy state before decaying.
Fundamental parameters
The rotation of the star causes a Doppler shift effect on the line spectra making it broaden. The faster the rotation, the broader (yet smaller) the line. Like the Uncertainty Principle, this is natural broadening as it doesn't impact the abundance of any particular element in the star.
Measuring the rotational velocity ($V_{\text{proj}}$) depends on both its axis of rotation and our line of sight to the star. Therefore, we use a combination of both velocity about the equator ($v_e$) and the star’s polar inclination ($i$) to determine the projected radial velocity;
$$V_{\text{proj}} = v_e \sin i$$
Temperature ($T_{eff}$)impacts wavelength in such a way that higher temperatures impart higher random motions on the atoms. When these photons collide with an atom, they can cause the atom to become ionised, i.e. lose an electron. Different energy levels (and therefore temperature) will create different abundances at the various ionisation stages of atoms.
The temperature of the stellar photosphere decreases as we move away from the core. Therefore the line profile represents a range of temperatures. The wings of the line arise from deeper, hotter gas which displays a larger range of wavelengths due to increased motion. The higher the temperature, the broader the wings of the line profile ([Robinson 2007, pg 58][1]).
Here you can see the effect of various temperature values on the synthetic spectral line of FE I 6593 A. Red: $T_{eff}$ = 4000K; Black: $T_{eff}$ = 5217K; Blue: $T_{eff}$ = 6000K;
$T_{eff}$ on spectral lines" />
Microturbulence ($v_{\text{mic}}$) is the non-thermal localised random motion of the stellar atmosphere. It works in a similar way to temperature - an increase in the motion of atoms creates a wider range of wavelengths observed and therefore broader line profiles.
In strong lines, saturation can occur when there aren’t any more photons to be absorbed. As microturbulence in these areas increases, it presents more opportunities for photons to be absorbed. This broadens the wings of the line profile increasing the overall strength of the line. We can use this fact to determine $v_{\text{mic}}$, by ensuring that the strength of the lines (equivalent width) have no correlation with their abundances.
Finally, surface gravity which is a function of the star’s mass and size:
$$\log g = \log M - 2 \log R + 4.437$$
with $M, R$ being in solar units and $g$ in cgs.
A star with a higher mass but smaller radius will invariably be denser and under greater pressure. By definition, denser gas has a higher number of atoms per unit of area (abundance), leading to stronger spectral lines.
A gas under pressure provides more opportunities for free electrons to recombine with ionised atoms. For a given temperature, ionisation is expected to decrease with an increase of surface gravity, in turn increasing the abundance of atoms in the neutral or low ionisation states.
The measuring of $T_{eff}$
As we've seen, there are a number of ways in which a spectrum of a star can be altered. The one you're interested in is temperature. As temperature is interrelated to all the other fundamental parameters, we need to treat them together as a whole and tease out the value of $T_{eff}$.
We begin with a synthetic spectrum and modify its properties iteratively until it matches the shape of the star’s spectrum. Adjustments of one parameter will invariably affect the others. The spectra will match when the temperature, surface gravity, and microturbulence values (amongst others) are correct. This is obviously very time consuming although programs exist to help.
Atmospheric properties can also be determined by other less time consuming means. Photometric colours can be used as a proxy for temperature, and absolute magnitudes for surface gravity. However, these determinations can suffer from inaccuracies due to interstellar extinction and are at best a close approximation.
[1] Robinson, K. 2007, Spectroscopy: The Key to the Stars (Springer)