Question: When can the police ask you for your identification?

I was about to go repelling off a suspension bridge in [place deleted]. A cop came up and told us it was illegal. We stopped setting up, and as we were about to leave, he asked all of us our names, s.s.number, address. One of us tried to refuse; the cop then threatened us with arrest (for "loitering"). We gave him the info. Then he took my friend to the back of his police car, called the FBI (my friend is a local anarchist/organizer), took his photo, and after 15 min, let him go. Is this legal?