Orin S. Kerr, a law professor at George Washington University who is an expert on digital searches and seizures, said Facebook was trying to do something unusual in establishing a right for service providers to challenge a warrant. "The real question is, 'Can they challenge warrants for their customers?' And I think the answer is probably not, under current law," Mr. Kerr said.
Chris Sonderby, deputy general counsel for Facebook, said that if Facebook could not challenge the warrants and the users remained in the dark, no one would ever get the chance to object to the possible invasion of privacy. "It appeared to us from the outset that there would be a large number of people who were never charged in this case," he said. "The district attorney's response was that those people would have their day in court. There are more than 300 people that will never have that chance."
Read More What companies are doing with your intimate social data
Mr. Sonderby said that the district attorney's demand for data was far larger than anything it had ever received from any other prosecutor. And Mr. Vance's office was unwilling to discuss narrowing the scope of its requests to be more directly relevant to its investigation.
The relationship was so chilly, said Mr. Sonderby, that when Facebook pressed its challenge to the warrants, one of the prosecutors called and threatened to press criminal contempt of court charges against the company and throw its officials in jail. "I've never seen anything like it," he said.
The district attorney's office said that about 600 possible suspects have been identified, and the investigation was continuing. Prosecutors said they had provided Supreme Court Justice Melissa C. Jackson with a 93-page affidavit with evidence to support each of the individual warrants, including information from wiretaps and documents filed with the Social Security Administration. They also maintain almost everything in the Facebook pages was relevant, since the people targeted in the investigation were faking mental illnesses to obtain benefits and had claimed to be too sick to leave the house, travel or work.
Read More Facebook faces suit over data allegations
Justice Jackson, in denying Facebook's effort to quash the warrants, said that the government must be granted some latitude. "In the course of a long-term criminal investigation, the relevance or irrelevance of items seized within the scope of a search warrant may be unclear and require further investigatory steps," she wrote.
In its appeal, Facebook disagreed vehemently.
"The government's bulk warrants, which demand 'all' communications and information in 24 broad categories from the 381 targeted accounts, are the digital equivalent of seizing everything in someone's home. Except here, it is not a single home but an entire neighborhood of nearly 400 homes," Facebook wrote in a brief to the appeals court. "The vast scope of the government's search and seizure here would be unthinkable in the physical world."
Read More Why online privacy is a big oxymoron
In a somewhat similar case in 2012, Manhattan prosecutors issued a subpoena to Twitter, demanding that it turn over deleted messages that had been posted by an Occupy Wall Street protester. In that case, a judge ruled that the protester had no standing to contest the data request. Twitter resisted the request but was ultimately ordered to turn over the information.
Lee Rowland, a lawyer with the American Civil Liberties Union, said the breadth of the search warrants, which had no time limits or any limits on topics, was troubling. It strains belief, she said, that every posting, picture and message in the Facebook files turned over to the state were necessary to the case.
"It's incredibly important in the digital context to prevent government fishing expeditions," she said.
—Vindu Goel and James C. McKinley Jr., The New York Times