The best sellers he did were done shortly before he started his run for President.
Dreams From My Father was written in 1992, and published in 1995. Obama ran for President in 2008, so 16 years after he wrote the book, and 13 years after it was published. The writing of the book led to him being President, not the other way around.
For Obama to hire a ghostwriter, you have to prove that a highly indebted new graduate, somehow hired a ghostwriter.
They were neighbors. Obama started his campaign for state senate in Ayers' living room.
They both lived a few miles apart in Hyde Park, but Obama did not move to Hyde Park until 2005. The book was written 13 years beforehand.
The two met on the Chicago Annenberg Challenge board meeting on March 15, 1995. It is uncertain how much they met, but that was the first time they were in the same room. The final manuscript of the book was accepted a year beforehand, and so there is no way Ayers could have altered any of it.
Obama did have a fundraiser in Ayers' living room, but it was not the start of his campaign.
He wrote the books for someone who was currently a US senator and about to run for President.
Once again, the book was written in 1992, the final manuscript was accepted in 1994, and it was published in 1995. It was well over a decade later that Obama was a US Senator, and ran for President. At the time the book was written, Obama was a nobody, with a great education, and a lot of debt from that education. He used his book writing ability to rise up from that.