Former US President Barack Obama has lifted the lid on his experiences during his visit to Kenya in 2006 while serving as the Illinois Senator.

In the first volume of a memoir series about his time as President from 2009 to 2017, Obama reflects on his trip to Kenya saying his family was “surprised” at the reception.

“We were surprised to see people lined up and waving alongside miles of highway,” Obama says of the crowds who turned up to welcome him when he traveled to his Kogalo village, his father’s ancestral home.

Obama, then a freshman Democratic senator from Illinois, was in Kenya as part of a tightly scripted four-country tour in Africa to raise awareness on AIDS and to reconnect with his roots.

During his highly publicized visit, thousands of people lined up along major roads to give what was then described as a heroic welcome to the son of the soil.

However, in his new book titled “A promised Land”, Obama recalls that at some point during his trip, his security detail got a rough time trying to protect him and his family.

Obama was then accompanied by his wife Michelle and daughters Sasha and Malia and family friend Anita Blanchard and her children.

“Only when we went on safari, parked among the lions and wildebeests, did we escape the commotion,” Obama writes of the relief they got when they visited Base Camp Masai Mara in Mara National Reserve.

Obama who has dedicated a big chunk of his new book to the events that led to his decision to run for US president reveals that the crowds caused some security scares.

Former President Barack Obama and Michelle Obama./FILE

A riot nearly broke out when he slipped past his bodyguards at some event but Obama simply smiled at the crowd.

“And when Michelle and I stopped at a mobile health clinic to publicly take an HIV test as a means of demonstrating its safety, a crowd of thousands showed up, swamping our vehicle and giving the diplomatic security team a real scare,” Obama writes.

During his visit, thousands of people had lined the streets, waiting hours in the intense sunshine just for a glimpse of Obama with shutter-snapping journalists and mobs of ecstatic fans on the trail.

Major local newspapers overflowed with breathless coverage, with a daily headline reading, “Village beats the drums for returning son.”

Obama describes Kenyan newspapers’ coverage of his visit as having been “over the top”.

During the week-long visit in 2006, Obama gave a lecture at the University of Nairobi where he criticized the Kenyan government’s inability to fight corruption and negative ethnicity.

Current Machakos Governor Alfred Mutua, then government spokesman, chided Obama, claiming a junior officer could not lecture the Kenyan government on corruption and tribalism.

Obama explains in his book that the family trip to Kogalo was thoughtfully organized by his half-sister Auma so they could introduce Sasha and Malia to “our father’s ancestral home.”

Obama later made history when in 2015 he became the first sitting US president to visit Kenya – but it was the fourth trip to his father’s home country.

The 2015 visit, more than 25 years after his first, brought a very different Obama face-to-face with a very different country and people.

In 1988, at just 27 years old, Obama had arrived in Nairobi for the first time.

He was on a journey of self-discovery to learn more about his heritage and his father, who was Kenyan.

But when his flight landed in an empty airport, he felt “tired” and “abandoned,” Obama wrote in his memoir, “Dreams From My Father.”

On his second trip in 1992, Obama traveled with his new fiance, Michelle, as a young lawyer before they were married that October.

Obama would later joke in one biography that he had to make sure he had his paternal grandmother’s approval before tying the knot with Michelle.

In his 2006 visit, Obama was greeted with much fanfare and was able to move relatively freely even into Kibera slums where he says in his latest book thousands packed themselves along the winding “paths of red dirt.”

But when Obama returned in 2015 it was strictly business. He was not accompanied by the first family, and his schedule was packed with meetings, conferences, and state dinners.

In “A promised Land”, Obama lays bare the struggles he fought – from the rumors to convincing his wife Michelle, before he finally declared his White House bid in 2006.

His formal announcement, Obama says, was preceded by various rumors that bubbled up on conservative media.

For instance, he says, there were reports that he had been schooled in an Indonesian madrassa, a claim that gained enough traction that a CNN correspondent actually traveled to his old elementary school in Jakarta.

Obama says the reporter found a bunch of kids wearing Western-style uniforms and listening to New Kids on the Block on their iPods.

“There were claims that I wasn’t an American citizen (helpfully illustrated by a picture of me wearing an African outfit at my Kenyan half-brother’s wedding),’” he says.

As the campaign progressed, Obama writes, more lurid falsehoods were circulated.

“These had nothing to do with my nationality but everything to do with a “foreignness” of a more familiar, homegrown, dark-hued variety: that I had dealt drugs, that I had worked as a gay prostitute, that I had Marxist ties and had fathered multiple children out of wedlock,” he says.