I am trying to programmatically create a group node and add a user to that group in Drupal 7. The group node is being created just fine but the user is not being added to the group and I am not getting any errors. I am guessing I am using the og_group function incorrectly but I am not sure. What am I doing wrong?
function MYMODULE_form_submit($form_id, $form_values) {
global $user;
$node = new stdClass();
$node->type = "group";
$node->uid = $user->uid;
$node->title = t("Group Node Title");
$node->body = t("Group Node Body");
$node->status = 1;
$node->promote = 0;
$node->comment = 1;
$node->og_description = t("OG Description");
$node->og_register = 0;
$node->og_directory = 0;
$node->og_private = 1;
$node->og_selective = 3;
$node = node_submit($node);
node_save($node);
$account = user_load(2);
og_group($node->nid, array(
"entity type" => "user",
"entity" => $account,
"membership type" => "OG_MEMBERSHIP_TYPE_DEFAULT",
));
drupal_set_message(t("Finished"));
}