How to programmatically populate a country field
I played around with this now for a little while. Seems all you need is the iso2 key to be set.

global $user;

$node = new stdClass();
$node-&gt;title = 'Lorem Ipsum';
$node-&gt;type = 'article';
node_object_prepare($node);

$node-&gt;language = LANGUAGE_NONE;
$node-&gt;uid = $user-&gt;uid;
$node-&gt;status = 1;

// In the end this was it.
$node-&gt;field_country[LANGUAGE_NONE][] = [
  'iso2' =&gt; 'FR',
];

$node = node_submit($node);
node_save($node);




Apart from that you can use the Devel module to either dump variables like that

dpm($variables);


for example in a MYMODULE_preprocess_node() hook. After you filled out a node with a country field from the UI you can use that to check which values are set. Or you can checkout node values directly by appending /devel to a node path (http://example.com/node/42/devel). Although I must admit that what I got there as output was quite misleading. All that really was needed was the iso2 key.