I would like to add a couple remarks to the good answer provided by James and to the comment of LutzL. First remark is that this falls under the problem of the trigonometric interpolation; we are requiring to find an interpolating trigonometric polynomial that equals the given one.
The solution given by James can be interpreted in terms of the discrete Fourier transform (for which I just discovered an excellent introduction at the end of the first volume of Princeton's lectures in analysis).
Preliminaries. We consider the additive group $\mathbb Z /N\mathbb Z$, in which integers are identified if they are equal modulo $N$; that is, $k= h \mod N\iff k=h+nN$ for some $n\in\mathbb Z$. We write $L^2(\mathbb Z/N\mathbb Z)$ for the space of complex valued functions on $\mathbb Z/N\mathbb Z)$, to remark that we have a scalar product given by
$$(F, G)=\frac{1}{N}\sum_{k\in \mathbb Z/N\mathbb Z} F(k)\overline{G(k)}.$$
The system of functions
$$
e_n(k):=\exp\, \left(i\frac{2\pi}{N}nk\right),$$ where $n\in\mathbb Z/N\mathbb Z$, is orthonormal on $L^2(\mathbb Z/N\mathbb Z)$, so every function $F\in L^2(\mathbb Z/N\mathbb Z)$ decomposes as follows:
$$ F(n)=\sum_{k\in \mathbb Z/N\mathbb Z} \hat{F}(k)e_k(n), $$
where $\hat{F}(k)=(F, e_n)$. This is the Fourier inversion formula.
The relevance of all of this to our problem is that every $2\pi$-periodic function $P\colon \mathbb R\to \mathbb C$ induces a function $Q\in L^2(\mathbb Z/N\mathbb Z)$ by setting
$$
Q(n):=P\left( \frac{2\pi}{N}n\right),\quad n\in \mathbb Z /N\mathbb Z.$$
We apply this to $P_M(t)=\sum_{k=-M}^M c_k e^{ikt}$, a trigonometric polynomial of degree $M$. Setting $N:=2M+1$ we have that, on the one hand,
$$Q(n)=\sum_{k=-M}^M \hat{Q}_M(k)e_k(n),$$
by the Fourier inversion formula. On the other hand, by definition,
$$Q(n)=P_M\left( \frac{2\pi}{N}n\right)=\sum_{k=-M}^M c_k e_k(n).$$ Therefore, equating the last two formulas, we have that
$$c_k=(Q, e_k)=\frac{1}{N}\sum_{n\in \mathbb Z/N\mathbb Z} P_M\left(\frac{2\pi}{N}n\right)\exp\left(-i\frac{2\pi}{N}nk\right),$$
which is the solution James gave.
The number $N=2M+1$ is the minimal one such that the last formula holds true for all trigonometric polynomials of degree $M$; indeed, the space of such trigonometric polynomials has dimension $2M+1$, which equals the dimension of $L^2(\mathbb Z/(2M+1)\mathbb Z)$. It is probably the case that the last formula holds true if $N$ is replaced by any larger integer, but I don't want to go into this.