Stephen Shankland/CNET

Six years ago, Twitter sued the US government in an attempt to detail surveillance requests the company had received, but a federal judge on Friday ruled in favor of the government's case that detailing the requests would jeopardize the country's safety.

If Twitter revealed the number of surveillance requests it received each calendar quarter, it "would be likely to lead to grave or imminent harm to the national security," US District Judge Yvonne Gonzalez Rogers concluded after reviewing classified information from the government. See below for the full ruling.

"While we are disappointed with the court's decision, we will continue to fight for transparency," Twitter said in a statement Saturday.

The ruling shows the difficulties of balancing privacy and and security on the internet. Public posts and private communications have opened up a treasure trove of information that law enforcement and intelligence services can investigate, and people may not suspect the government is listening in. On the other hand, encryption technology also has opened up communication conduits that are fundamentally impenetrable to government and law enforcement.

In Twitter's transparency report, now updated for six-month periods, the company publishes numbers on law enforcement information requests, copyright infringement allegations, attempts to spread disinformation, reports of abuse, and other goings-on. The company argued in its 2014 lawsuit it shouldn't be barred from revealing detailed tallies of national security-related information requests.

"We think the government's restriction on our speech not only unfairly impacts our users' privacy, but also violates our First Amendment right to free expression and open discussion of government affairs," Twitter argued at the time.

Six years later, Twitter says transparency is still important to show how it interacts with governments.

"Transparency is a key guiding principle in Twitter's mission to serve the public conversation. Freedom of expression is the cornerstone of why we exist, and we strive at all times to help those who use our service and the general public understand how governments, including in the United States, interact with our company," Twitter said in its statement. "We believe it is vital that the public see the demands we receive, and how we work to strike a balance between respecting local law, supporting people's ability to Tweet, and protecting people from harm."