Sending messages from php loop problem


#1

I’m trying to send few selected replies from my forum admin tool to my twitter page
using php tmhOAuth class

require_once ‘…/include/tmhOAuth.php’;
require_once ‘…/include/tmhUtilities.php’;

     foreach($replies as $id => $item)
     {
   
            $tmhOAuth = new tmhOAuth(array(
                                                                      'consumer_key'    => 'my_consumer_key',
                                                                      'consumer_secret' => 'my_consume_secret',
                                                                      'user_token'      => 'my_user_token',
                                                                      'user_secret'     => 'my_user_secret' ));
              
                   
                $message=getMesssage($id);
                   
                if(strlen($message)>140)
                {
                    $message=substr($pmessage,0,140);
               
                }
        
           
                $code = $tmhOAuth->request('POST', $tmhOAuth->url('1/statuses/update'), array('status' => $message));
            
              
                if ($code != 200)
                {
                    tmhUtilities::pr($tmhOAuth->response['response']."=>".$message);
               
                }
           

}    

When i select only one reply and send it - all works OK.
BUT if i select few replies and send them from foreach loop as shown above -I get error for part of messages.

“error”:“Could not authenticate with OAuth.”,“request”:"/1/statuses/update.json

Why? What’s wrong in my code here? Should i do any delay when i send twitter messages from foreach loop -or there is something else ?