An Australian politician says he has learned a valuable lesson in social networking after he "liked" a Facebook photo without realising that it showed a teenage prankster exposing himself.

Western Australia's minister for education, Peter Collier, said he clicked the "like" button under what he thought was an innocent photo of the then 16-year-old in late 2011.

Collier apologised on Thursday and said he had no idea that the teenager, who was otherwise fully clothed and posing alongside an older man, was playing a prank commonly known as "sneaky nuts".

"At first glance it appeared to be a harmless picture," Collier said in a statement. "It was a silly mistake on my part. I only became aware of the actual content of the photo when shown by a journalist today. This obviously highlights the pitfalls of social media. I apologise if I caused any offence."

The stunt was popularised by Australian comedian Chris Lilley's TV show Angry Boys, in which a character revels in ruining group photos by secretly exposing himself. The prank has been a headache for some educators: last year, administrators at a Catholic school in Canada scrambled to place stickers over a photo printed in 1,300 class yearbooks of a student subtly exposing his genitals.

The Australian incident did not attract attention until late last month, when the teenager bragged on Twitter about fooling Collier, with whom he was friends on Facebook.