When James Dyer approached a U.S. Customs and Border Protection officer at Los Angeles International Airport on Thursday, he was just another traveler passing through the bustling hub. But then Dyer said he presented his journalist visa to the agent and what should have been a routine immigration stop quickly transformed into “an unsettling experience.”

In a lengthy Twitter thread that has since gone viral, Dyer, who covers film and TV for Empire magazine in the United Kingdom, detailed how the CBP agent accused him of “being part of the ‘fake news media’ ” before launching into a “surprising and inappropriate” diatribe that echoed rhetoric used by President Trump in his frequent attacks against the media. Dyer told The Washington Post he had flown from London to Los Angeles for Disney’s D23 Expo in Anaheim, Calif., where he plans to write about Star Wars.

“He wanted to know if I’d ever worked for CNN or MSNBC or other outlets that are ‘spreading lies to the American people,’ ” Dyer tweeted, referencing two media organizations Trump has repeatedly blasted as “fake news.” “He aggressively told me that journalists are liars and are attacking their democracy.”

A CBP spokesperson told The Post late Thursday that the agency was aware of Dyer’s experience.

“All CBP officers take an Oath of Office, a solemn pledge that conveys great responsibility and one that should be carried out at all times with the utmost professionalism,” the statement said. “Inappropriate comments or behavior are not tolerated, and do not reflect our values of vigilance, integrity and professionalism.”

Dyer’s account comes as CBP agents have been repeatedly accused of verbally harassing and, in at least one case, detaining traveling journalists. In April, the United States’ ranking in the annual World Freedom Press Index dropped for a third year in a row, a decline researchers attributed to Trump’s incendiary language, The Washington Post’s Paul Farhi reported. This year, for the first time since the index was launched in 2002, the treatment of journalists in the United States was classified as “problematic.”

On Thursday, Dyer told The Post in Twitter messages that he has discussed politics with customs officers in the past, but none of the conversations were quite like what he experienced at LAX.

“I hugely disagree with what the guy said as I’m a woolly liberal and I find that kind of Trumpian propaganda depressing but I respect his right to have different views,” he wrote. “I do think it’s inappropriate (in the extreme) to articulate those views to a foreign journalist upon arrival in his capacity as an officer but I’m not looking to get him fired for it.”

Dyer added that CBP should “maybe communicate that this kind of thing is unacceptable to its officers generally.”

The tweets detailing the exchange sparked instant outrage as many advised Dyer to report the officer and lambasted the agency for the man’s “unacceptable” behavior. In response to the incident, CBP Los Angeles also tweeted at Dyer, writing, “We strongly advise you to file a formal complaint.”

But the journalist quickly clarified that while the interaction had been “unsettling,” he wasn’t “mistreated or detained in any way.”

“He let me go after I said that I was just here to write about Star Wars, and would keep the fake news about that to a bare minimum,” Dyer tweeted, noting that the pair only talked for a couple of minutes at the kiosk where travelers are fingerprinted and have their documents checked.

Dyer is just the latest journalist to recount a negative experience with a CBP agent this year. In February, David Mack, BuzzFeed News’ deputy breaking news director, tweeted that he was “grilled” for 10 minutes while going through immigration at John F. Kennedy International Airport in New York. Mack tweeted that the agent noticed he worked for BuzzFeed and began questioning him about a hotly disputed story the outlet had published about Trump, his former attorney Michael Cohen and the Russia investigation. CBP later apologized to Mack “for the inappropriate remarks made to him during his CBP processing upon his arrival to the United States.”

A few months later, Seth Harp, a contributing editor at Rolling Stone, published a detailed account in the Intercept describing how he was not only questioned about his job while traveling through an Austin airport, but also detained for hours and searched. Harp wrote that in May he was on his way back from a Mexico City reporting trip when he was pulled aside for secondary screening. Agents went through his belongings, which included “reading every page”of his journal and examining his laptop and phone without a warrant, he wrote. Citing privacy laws, CBP told KXAN that the agency could not provide “specific information regarding an individual traveler” but noted that a passenger “who refuses to respond to CBP officer questions” is usually “referred for additional processing.”

Though Dyer stressed that the CBP agent was within his rights to express his views, the journalist suggested the incident was a sign of the times. As the agent ranted about the media, Dyer tweeted that a CBP sign posted nearby read, “we are the face of our nation” and there was a “framed picture of 45 staring down,” referring to Trump, the 45th president.

“This isn’t news but the malignant affect this presidency has had on what was once a beacon of democracy and freedom is absolutely chilling,” he tweeted.