A former Twitter employee found guilty of spying on users on behalf of the Saudi royal family has been sentenced to three and a half years in prison.