Is there any Google API which would return all the countries in the world with the country code?
The Google Maps API family does not have anything like this. There might be other API's that do, but since ISO 3166-1 is fairly static you are probably better off embedding the data rather than retrieving it from an API every time you need it.
You could use Wikipedia's article on ISO 3166-1 as a source for the list of countries and codes.
How about KML Countries at GeoCommons. It has entries such as:
- Cntryname: Australia, Fipscntry: AS
- Cntryname: Egypt, Fipscntry: EG
- Cntryname: France, Fipscntry: FR
- Cntryname: United States, Fipscntry: US