If a police officer stops you and is detaining you for something then yes they have to give out their name and badge number to the person they're talking too.
If the police officer stops you while walking or riding your bicycle then you do not have to give your ID or name or anything unless the officer is stopping you for a crime that has been committed.
A police officer must say they're detaining you before they can legally force you to stay and talk to them.