Why would a presidential candidate spend more time campaigning in states like California Texas or New York?

States with the greater population are given more electoral votes. California is given 55, Texas is given 38, and New York is given 29 electoral votes. To win the presidency, a candidate must get a total of at least 270 electoral votes. So naturally candidates will try to capture the majority votes of the most populous states. However, in recent elections candidates spend little time in California, New York (liberal states), and Texas (a conservative state) because their allegiance to political parties is predictable. Candidates generally only visit these states to raise money. Instead, candidates campaign in "swing" states (states that could go either way) such as Ohio, Florida, and North Carolina.