ALEXANDRIA, Virginia (Reuters) - A Michigan man was sentenced on Friday to four years in prison for trying to get a job with the CIA so he could spy for China, just as Chinese President Hu Jintao was wrapping up his U.S. visit.

Glenn Shriver, 29, pleaded guilty in October to conspiracy to communicate national defense information after admitting he met Chinese officials about 20 times and took about $70,000 from Chinese intelligence officers.

Shriver said at the sentencing hearing he made a “terrible decision” to try to spy for China and “somewhere along the way I got into bed with the wrong people.”

U.S. District Judge Liam O’Grady sentenced Shriver to four years in prison, as called for in the plea agreement, followed by two years of supervised release.

“Mr. Shriver sold out his country and repeatedly sought a position in our intelligence community so that he could provide classified information to the PRC (People’s Republic of China),” U.S. Attorney Neil MacBride said in a statement.

Prosecutors said Shriver was caught before he could begin working at the Central Intelligence Agency and that he never was close to getting access to classified information.

Shriver spent a year during college studying in Shanghai in 2002-2003 and moved there in 2004 to continue his studies and to work. Prosecutors said he responded to an advertisement for a writer on U.S.-Sino relations and the contact he met later introduced him to Chinese intelligence agents.

Shriver took the U.S. Foreign Service exam twice at the State Department, failing both times, but the Chinese still paid him $30,000 for his “friendship” and efforts, according to court papers.

He then applied for a job in the CIA’s National Clandestine Service and demanded $40,000 from the Chinese intelligence officers, according to prosecutors.

During his final employment processing last May, he failed to disclose his contacts and the money he received.

Shriver said he considered the initial contacts “very innocuous” and the offers of money were explained to him as a stipend for living expenses. He said only once did the Chinese contacts say they wanted U.S. secrets.

The sentencing came as Hu wrapped up a four-day visit to the United States that included talks with President Barack Obama and the announcement of numerous commercial deals.

Relations between the two countries have been strained at times over issues including China’s currency policies and its position as the largest foreign holder of U.S. debt, as well as tensions over the nuclear ambitions of Iran and North Korea.