A man accused of stalking Taylor Swift has been ordered to serve up to four years in prison.