i think i found a solution
function add_post($title, $content){
// Create post object wp_strip_all_tags
if (!is_user_logged_in()){
$user_id = 1;
wp_set_current_user($user_id,$user_login);
wp_set_auth_cookie($user_id);
do_action('wp_login',$user_login);
}
$my_post = array(
'post_title' => $title,
'post_content' => $content,
'post_name' => sanitize_title($title),
'post_status' => 'publish',
// 'post_author' => 1,
'post_category' => array(1)
);
// Insert the post into the database
wp_insert_post( $my_post );
}