It sounds like this 2004 Toyota Camry failed the smog check because it's Emission Monitors were not READY, at the time of the smog test. Emission Monitors are internal self-tests which a vehicle's computer performs in order to ensure all emission systems are functioning properly.
Whenever a vehicle's battery is disconnected or computer trouble codes cleared, the emission monitors are RESET. The vehicle needs to be drive for approximately 200-300 miles in city and highway traffic conditions, and over the course of a few days, in order for the emission monitors to become READY or COMPLETE. The emission monitors will only become ready if and when all emissions systems are functioning properly.
As far as the purchase of this 2004 Toyota Camry... Section 24007 (b)(2) of the Vehicle Code states it is the responsibility of the seller to provide a valid smog certificate at the time of delivery of the vehicle. You may contact the seller, advise them of this CA law and attempt to remedy the situation amicably. If the seller is not willing to help, the small claims courts are always at your disposal.