How did Mexico get California from Spain?

Mexico did not get California from Spain; California became a part of the United States after the Mexican-American War in 1848.
Copyright Wanderlust World © https://www.ynyoo.com