Yes, you can earn miles when you book with a TA.
Also, if you forget to give your number to the TA or the airline, you can still get credit for the miles after your trip. Just make sure to keep the boarding pass stubs from your flights. When you get home, contact your airline and they'll tell you what you need to do to get the miles.