Which us president was gay

James Buchanan was the only U.S. president who remained a bachelor throughout his life. Buchanan had a close relationship with William Rufus De Vane King, sparking speculation about his sexuality. Historian James Loewen suggests Buchanan's possible gay identity is not widely discussed today.
Was his close friendship with William Rufus King just that, or was it evidence that he was the nation's first gay chief executive?.