Canadian government departments have quietly blocked nearly 22,000 Facebook and Twitter users, with Global Affairs Canada accounting for nearly 20,000 of the blocked accounts, CBC News has learned.

Moreover, nearly 1,500 posts — a combination of official messages and comments from readers — have been deleted from various government social media accounts since January 2016.

However, there could be even more blocked accounts and deleted posts. In answer to questions tabled by Opposition MPs in the House of Commons, several departments said they don't keep track of how often they block users or delete posts.

It is not known how many of the affected people are Canadian.

It's also not known how many posts were deleted or users were blocked prior to the arrival of Prime Minister Justin Trudeau's government.

But the numbers shed new light on how Ottawa navigates the world of social media — where it can be difficult to strike a balance between reaching out to Canadians while preventing government accounts from becoming a destination for porn, hate speech and abuse.

The numbers came as Environment Minister Catherine McKenna found herself in a social media firestorm over a tweet from her official departmental account on Tuesday which praised Syria for joining the Paris climate change agreement.

Minister of Environment and Climate Change Catherine McKenna came under fire Tuesday for a tweet from her departmental account praising Syria for joining the Paris climate accord. (Jonathan Hayward/Canadian Press)

But while McKenna announced very publicly that that tweet had been deleted, the numbers tabled in the House of Commons reveal there were 97 other posts deleted from that department's accounts between Jan. 1, 2016 and Sept. 18, 2017.

In the department's answer, signed by McKenna, it said posts were deleted that were inconsistent with Treasury Board guidelines or "when it was necessary to correct errors in information, grammar or visual imagery, to clarify or more accurately reflect a priority, or to ensure adequate service in both official languages." The Treasury Board sets rules for government communications, including social media.

"Social media moves quickly and sometimes mistakes happen."

But the environment department isn't the only one that has deleted an awkward tweet.

The Canadian Nuclear Safety Commission deleted two of them.

One tweet didn't meet Treasury Board guidelines. The other, which expressed a Happy Bastille Day to France, was considered "insensitive and untimely following reports of a terrorist attack at a Bastille Day celebration in Nice, France."

The Treasury Board occasionally deletes posts, but says it doesn't track deletions. It did away with one particular Facebook post because it included a photo of someone who had died.

Chrystia Freeland's Global Affairs department has blocked more social media users than all other government departments combined. (Sean Kilpatrick/Canadian Press)

The Canadian Transportation Agency deleted one comment on its Facebook page — repeatedly.

"The post in question was uploaded to the agency's site hundreds of times and linked to a statement containing references to specific staff of the agency that impugned their integrity and professionalism," the agency said.

The agency's comment appears to refer to an online dispute it has been waging with air passenger rights advocate Gabor Lukacs.

Canada Post reported deleting more posts than any other government department or agency, wiping out 845 comments on Facebook and 20 on Instagram. Some were spam or had typos. Others promoted Canada Post's competitors.

Fisheries and Oceans reported it blocked 27 users since Nov. 4, 2015 — 22 of them for displaying pornographic content on the @DFO_NL account.

One way to delete a comment, as the Royal Canadian Mounted Police noted, is to have the user's account blocked.

Users blocked on Facebook can't see things posted on an account's profile, tag it in posts or start a conversation about it. Blocking a user on Twitter prevents them from following you, seeing your tweets or sending you a direct message.

Health Canada blocked 50 accounts, 37 of them for spamming about products like weight loss supplements.

Some Twitter users have been blocked by government departments for trying to post porn or hate. (Matt Rourke/Associated Press)

Global Affairs Canada blocked more social media users than all other departments combined, but downplayed the number in its answer tabled in the House of Commons.

"Global Affairs Canada has 568 social media accounts," it wrote. "This represents an average of 35 blocked users per account."

Canada's spy agency, the Canadian Security Intelligence Service blocked two users — one for sending pornography, the other for "abusive content."

Sometimes officials couldn't explain why some users were blocked.

The environment department blocked six Twitter accounts on Sept. 28, 2016, then couldn't figure out why.

"As such, they were unblocked on October 24, 2016," the department said.

Elizabeth Thompson can be reached at elizabeth.thompson@cbc.ca