Can't add taxonomy term to node? This code saves the taxonomy term, but it doesn't add it to the node.
What is the problem?

             $node = new stdClass(); // Create a new node object
            $node-&gt;type = "article"; // Or page, or whatever content type you like
            node_object_prepare($node); // Set some default values
            $node-&gt;language = en; // Or e.g. 'en' if locale is enabled
            $node-&gt;title = $title;
            $node-&gt;field_image['und'][0] = (array)$file;
            $node-&gt;uid = '1'; // UID of the author of the node; or use $node-&gt;name

            $tags = explode(",",$sended_tags);
            $vid = 1;

            $term = new stdClass();
            $term-&gt;name = $tags[0];
            $term-&gt;vid = $vid;
            taxonomy_term_save($term);


            $node-&gt;taxonomy[] = $term;

            node_save($node);
You can do it like this: 


if ($foo = taxonomy_get_term_by_name($term_name)) {
      $foo_keys = array_keys($foo);
      $node->your_taxonomy_field_name[LANGUAGE_NONE][]['tid'] = $foo_keys[0];  
    }
    else {
      $node->your_taxonomy_field_name[LANGUAGE_NONE][] = array (
        'vid' => 1,
        'tid' => 'autocreate',
        'name' => $term_name,
        'vocabulary_machine_name' => 'machine_name'
      );