Generally speaking: The flight needs to be operated by a *A carrier. There are a very few exceptions: e.g. Some flight operated by 9W booked under an AC flight number credited to AE used to earn miles, LY operated flights on the ZRH-TLV route booked as a LX codeshare credited to LH/LX M&M earn bonus miles only. But those exceptions probably only account for <0.1% of all codeshare flights.
Oneworld has a very different set of rules where the marketing carrier determines the number of miles earnt most of the time.
If the flight is booked as an UA codeshare operated by a OW airline, you won´t earn any miles with any OW FFP either because the flight was not marketed by a OW carrier. In that case you wouldn´t earn any miles in any program for that flight.