Could the U.S. have found a way to govern these big territories annexed from Spain in a way that would have left the natives content and not prone to riot and revolt?
In the Phillipines, I think you'd have to be willing to enact comprehensive land reform and pretty big infrastructure works fairly quickly. You also need a way for the US not to forcibly dissovle Aguinaldo's Philippine Republic in 1901. Perhaps the war with Spain goes on longer. Perhaps the American commander is switched for an analogue who decides to make use of the native forces. Best is that the US Gov't at the time decides / needs to appease anti-imperialist forces by proclaiming support for the independent governments and the US intent to guarantee the survival of both Aguinaldo's regime and the Cuban indepence movement. Then you need to have that regime falter / collapse, leading to the Americans being invited to take more control. Then you need a forward-thinking American in charge you manages to get the US to commit resources: perhaps a Russo-Japanese war that goes on longer leading to more Japanes advance might make the US seek to fortify and improve the Phillipines as a base.
You'd then need somekind of difference in 1941, though I'm not sure what. In some way, it'd be nice to have some expansionist Asian power for the Fillipinos to fear. OTL Japan was conquered and Comunist China hadn't come to power when independence was confirmed in 1948.
I think you'd have to let Cuba experiment with independent government. There's too much of a pro-indepence native population. You'd then need a good reason to have the US spend money developing Cuba more than it did OTL and a good reason to have Cuba fear some foreign power. Both are unlikely to happen, short of massive changes elsewhere.
One big problem is that both had strong feelings about independence and both had exploitable natural resources. The easiest way to ensure American control of the later was to concede the former. The same tactic was used in Haiti, the Domincan Republic, and other Banana Republics. You'd need a US government that felt some vested interest in controling the ravaging interests of the corporations at work.