SAN FRANCISCO — The California Supreme Court has ruled that Facebook and other social media companies must turn over user content that is public to criminal defendants.

The court on Thursday kicked the specific case back to the trial court to decide whether information requested by the defendants was open to the public - and, therefore, information that companies must provide.

Attorneys for the social media companies had argued that federal privacy law prevents the release of any user content and that the defendants had other ways to get the material.

The defendant also sought information from Twitter.

At issue are requests by a defendant accused in a San Francisco slaying who wants videos and other content posted to Facebook and Instagram by the victim and a witness. The defendant, Lee Sullivan, and a co-defendant, Derrick Hunter, also sought information from Twitter.

Prosecutors charged the two men with murder in an alleged gang-related drive-by-shooting in 2013. Sullivan said the witness was his former girlfriend, and her social media posts would show she was jealous and angry because Sullivan was involved with other women.

The defendants say their constitutional right to a fair trial entitles them to the social media records to prepare their case. Attorneys for the companies say a federal privacy law prevents the release of user content, and the defendants have other ways to get the material.

They could ask the witness for her social media content and get the victim's information from prosecutors, who obtained a search warrant for his Facebook and Instagram accounts and are required to turn over any exculpatory evidence to the defense, the company's attorneys, Eric Miller and James Snell, wrote in a brief to the California Supreme Court.

Sullivan's attorneys have said they could not locate the witness to serve her with a subpoena. Both defendants also say access only to records that support the prosecution's theory of the case does not allow them to mount a complete defense, according to a 2015 appeals court ruling.

That ruling sided with the social media companies and rejected Sullivan and Hunter's requests for information.

Google in a brief filed in the case warned that loosening the rules around releasing information would undermine users' confidence in the privacy of their communications and "greatly increase" its burden from requests to disclose user information.

San Francisco's public defender's office countered in its own brief that prosecutors are increasingly offering social media records as evidence and "defendants have a parallel need for these records to defend against charges."