After a few confusing tweets, U.S. President Donald Trump on Thursday pushed the House to renew a critical national security program that allows spy agencies to collect intelligence on foreign targets abroad.

Trump was referring to the reauthorization of the Foreign Intelligence Surveillance Act, which is set to expire on Jan. 19. The House ultimately voted to do so on Thursday, and the Senate must also act.

"This vote is about foreign surveillance of foreign bad guys on foreign land," Trump said in his second morning tweet on the matter. "We need it! Get smart!"

With that being said, I have personally directed the fix to the unmasking process since taking office and today’s vote is about foreign surveillance of foreign bad guys on foreign land. We need it! Get smart! —@realDonaldTrump

But two hours before that, he sent out a tweet suggesting that the program was used to collect information that might have been used to "badly surveil and abuse" his campaign.

On Wednesday, the White House issued a statement opposing changes to the program.

Rep. Adam Schiff of California, the ranking Democrat on the House intelligence committee, said Trump's tweets were "inaccurate, conflicting and confusing statements" and Schiff unsuccessfully suggested that a vote on the bill should be delayed until the White House's position can be ascertained.

House Speaker Paul Ryan, R-Wis., speaks during a news conference on Thursday, where he denied any contradiction in White House policy based on President Donald Trump's tweets on FISA surveillance. (Pablo Martinez Monsivais/Associated Press)

House Speaker Paul Ryan, in his weekly news conference, dismissed the notion that Trump didn't know the White House position.

"He's aware of it," said Ryan.

The Speaker said Trump is fully on board with the foreign surveillance aspect.

"It's well known that he has concerns about the domestic FISA law," said Ryan. "That's not what we're doing today. Today was 702, which is a different part of that law ... He knows that and he, I think, put out something that clarifies that."

Warrant for database queries rejected

The program, known as Section 702 of the Foreign Intelligence Surveillance Act, allows U.S. spy agencies to collect information on foreign targets outside the United States. Americans' communications are inadvertently swept up in the process and privacy advocates and some lawyers want to require the FBI to get a warrant if it wants to view information on Americans that is in the database to build domestic crime cases.

Edward Snowden, the controversial former NSA contractor whose leaks of troves of data helped reveal the scope of government surveillance, was among those opposed to the extension.

This is one of the most respected surveillance policy experts in America. The context is that Democrats are quietly joining with Republicans to grant expanded warrantless surveillance powers to Donald Trump. Right now. <a href="https://t.co/8lb58wZs3h">https://t.co/8lb58wZs3h</a> —@Snowden

The FBI, including current director Christopher Wray and predecessor James Comey, as well as the intelligence agencies, have said being able to query the database is essential to keeping the U.S. safe.

The House passed the bill to reauthorize FISA with an important tweak. It requires the FBI to get a warrant if it wants to view the contents of Americans' communications swept up in the process.

The bill passed 256-164.

The House earlier rejected, by 233-183, a measure that would have required the FBI to get a warrant to continue even querying the database when Americans are involved.

This <a href="https://twitter.com/hashtag/Section702?src=hash&ref_src=twsrc%5Etfw">#Section702</a> bill would give AG Jeff Sessions unchecked power to use this information against Americans. This bill prevents his decisions from EVER being challenged in court. —@RonWyden

If this <a href="https://twitter.com/hashtag/Section702?src=hash&ref_src=twsrc%5Etfw">#Section702</a> bill comes to the Senate, I will filibuster it. —@RonWyden

Most lawmakers expect it to become law, although it still would require Senate approval and Trump's signature. Republican Senator Rand Paul and Democratic Senator Ron Wyden immediately vowed to filibuster the measure but it was unclear whether they could convince enough colleagues to force changes.

On the heels of immigration confusion

It's not the first time this week that Trump's coherence on policy has come under question.

During a lengthy open-camera session concerning immigration with members of both parties, the president appeared to veer from his oft-stated position that the construction of a border security wall along the Mexico border had to be part of an agreement involving young immigrants.

"We are going to do DACA [Deferred Action for Childhood Arrivals], and then we then we can start immediately on the Phase 2 which would be comprehensive immigration — I would like that," Trump said.

Democratic Senator Dianne Feinstein sought clarification from Trump on the apparent interest in a multiphase approach before Kevin McCarthy interjected to better state the Republican position.

Trump also appeared to describe the extent of the border wall differently at various points in the meeting.

Critics have looked for patterns in Trump's tweets, suggesting they're sometimes influenced by Fox News coverage. Fox aired a segment on Thursday morning where controversial contributor Andrew Napolitano criticized FISA as the beginning of Trump's "woes" with respect to the investigations into Russia interference into the 2016 election that have embroiled his administration and family members.

Napolitano was suspended by the network last year for claiming, without evidence, that British intelligence officials had helped former president Barack Obama spy on Trump.