The best thing to do is alway cooperate fully with the officer... but take notes, mentally if not on paper, of everything, especially the officer's identity. Remember, there'll be plenty of time for sorting out the details later if necessary. Right now, just cooperate with the officer. Just being friendly and cooperative will often make things go easily.
In most cases, officers wear name tags. I always address them, respectfully mind you, by name. I say, "Yes officer Smith, No officer Smith." It's respectful and nice, but it's also a subtle way of letting the officer know that I have taken note of his name. It generally puts them on their best behavior.
If the officer wants to confiscate your property, cooperate, but insist on a receipt.
Ask for the officer's business card. Most departments issue them to officers and they'll give you one if you ask.
I'm also always quick to thank officers for their help and also to praise them to their chief when they are helpful and polite. Some years ago, I had a bit of a car accident. One of Sherwood's finest pulled up rather promptly and helped me out. He let me sit in his car out of the rain until the tow truck arrived. We chatted. He showed me their in-car computer terminals. Very impressive. He was very friendly and polite. He gave me his card. Later, I wrote a nice letter to our police chief praising this officer for being so helpful. Some time later, I was walking to the grocery store as I often do when a police officer on a motor cycle pulled up beside me. As he removed his helmet, I recognized him as the helpful officer from my accident. He said, "You're the fellow who went flying off Tonquine road a few months ago, aren't you?"
"Yes, and you're the helpful officer who assisted me. How nice to see you again."
"The chief read your letter in front of the entire department. That's why I got to be on the motorcycle patrol which I've wanted for years. Thank you!"