Spill the beans was used in horse-racing in St. Louis, MO, as early as 1902 and meant "to cause an upset". By 1907 it was being used with a similar meaning in baseball in other states.
The OED has spill the beans meaning "to reveal a secret" from 1919. The Phrase Finder has 1908 for the meaning of "upset the applecart" and 1911 for "upset a previously stable situation by talking out of turn".
The earliest I found is a 1902 beans were spilled in horse-racing, meaning "caused an upset", quoting owner E. J. Arnold.
The St. Louis Republic (St. Louis, MO), November 25, 1902:
"Ethylene was 15 to 1 one day and would
have won sure had Battiste been up. He
was set down by the starter in St. Louis
and I had to ride a bad boy. Then we put
Battiste up later and got down. Kiley told
him to take her back a bit. He did, and
in some manner the field ran around and
over her so that she was shut in, cut off
and lost. So the beans were spilled.
I found some 1903 examples, all from horse-racing meaning to cause an upset, and all in the same The St. Louis Republic.
The St. Louis Republic (St. Louis, MO), May 06, 1903:
KINGSTELLE SPILLED THE BEANS.
Every one fancied that the fifth race was
a two-horse one between Nearest and Audiphone, who were held at 4 to 5 and 8 to 5
respectively. Kingstelle, a 10-to-l shot,
broke it up. She laid away from the pace
and came along in the stretch, and won,
handily, a real nice race. Nearest and
Audiphone ran to a head finish. Nearest
getting the best of it. It was the third
time that these two horses met on equal
terms. Each time Nearest has beaten Audiphone by a head. This is form of a miraculous nature. The secret of it is that both
have been trying hard. Neither Mr. Flippen, who trains Audiphone, or Mr. Hughes,
who owns Nearest, is around stalling with
the old complaint: "Now, you know you
feel good one day and bad the next. That
is just like a horse."
The St. Louis Republic (St. Louis, MO), June 13, 1903:
St. Agnes II
has no business in here. Out with Bel
Coeur, a full sister to the French girl.
Her Folieship has no business in either, as
she is liable to run out and spill the beans.
The St. Louis Republic (St. Louis, MO), September 07, 1903:
Each Race Presents a Horse That
Seems to Hold His Field
STAKE RACE IS THE HARDEST.
Jordan Should Win on Form, but
Helen Print and W. B. Gates
Likely to Improve and
Spill the Beans.
The St. Louis Republic (St. Louis, MO), September 09, 1903:
He is not a consistent horse, judging from
his races. Neither did he get much of a
ride last time, when it seemed that Inglethrift was the "right" one. Lord Hermence came on and spilled the beans.
By 1907 the phrase had spread beyond Missouri and beyond horse-racing.
Here's baseball in The Democrat-Sentinel (Logan, Ohio), 29 Aug. 1907:
this point the game began to get
interesting, as Logan was just two
scores behind, and were beginning
to find Farrow's delivery with
ease, but the beans were spilled in
the eighth when Jones, who played
sensational ball all during the
game, erred on Murphy and Kelley, first two up, this followed by
stolen base and an error by Johnson at the plate and Farrow's
single were good for thee more
runs, bringing their total to nine,
just three more than Logan made
during the entire game.
Here's a pun in The Rice belt journal (Welsh, Calcasieu Parish, LA), 23 Aug. 1907 (also in VA):
Eat in haste and repent in pepsin.
Do not eat with your knife; it spills
A penny saved is a penny earned
by the doctor.
It was still used in horse-racing in 1907 (L.A. CA).
As The Phrase Finder shows by 1908 it was used outside sport meaning "to cause an upset". And by 1911 it was used in politics meaning "upset a previously stable situation by talking out of turn". World Wide Words has a 1910 "extension of the sports sense into upsetting a situation by speaking out". From there, the meaning evolved to the modern one, to reveal a secret which may cause an upset.