Top Poster
#1 ramon fincken 399
#2 Site admin 3
#3 Ber|Art 2
#4 braddmark 1
#5 accentmedia 1
#6 Xarzu 1
#7 pEcosespedex 1
#8 khadish 1
#9 moxxx 1
#10 nistelrock 1
[solution][snipplet] function update_twitter_status() using the API



Rating : 3 / 5

 
Post new topic   Reply to topic    Ramonfincken.com Forum Index -> PHP coding
Beta
Want to be notified by email when this topic gets a reply?  
View previous topic :: View next topic  
Author Message
ramon fincken
Site's programmer

Get a free globally recognized avatar
It's free!


Joined: 03 Aug 2007
Posts: 399
Location: A'dam/Diemen, The Netherlands

PostPosted: Mon May 24, 2010 11:59 am    Post subject: [solution][snipplet] function update_twitter_status() using the API Reply with quote

A simple function to update your twitter status using the API:

Thanks to http://woork.blogspot.com/2007/10/twitt...-page.html


Code:

/**
* A simple function using Curl to post (GET) to Twitter
* Kosso : March 14 2007 http://woork.blogspot.com/2007/10/twitter-send-message-from-php-page.html
* Ramon Fincken http://www.ramonfincken.com/permalink/topic215.html
* Warning: make sure your message is not more then 140 chars!
*/
function update_twitter_status($username,$password,$message,$mailto = NULL){

   $message = substr($message, 0, 140);
   $host = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message)));

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $host);
   curl_setopt($ch, CURLOPT_VERBOSE, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
   curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
   curl_setopt($ch, CURLOPT_POST, 1);

   $result = curl_exec($ch);
    // Look at the returned header
   $resultArray = curl_getinfo($ch);

   curl_close($ch);

   if($resultArray['http_code'] == "200"){
         $twitter_status='Your message has been sended! <a>See your profile</a> http://twitter.com/' . $username;
   } else {
      $twitter_status="Error posting to Twitter. Retry";
   }
   if(isset($mailto))
   {
      mail($mailto, 'twitter sent', $twitter_status);
   }
   return $twitter_status;
}
Back to top
View user's profile Send private message Visit poster's website
Google adsense
Advertisement





PostPosted: Mon May 24, 2010 11:59 am    Post subject: [solution][snipplet] function update_twitter_status() using the API

Advertisement
Back to top
GravityForms
Advertisement





PostPosted: Mon May 24, 2010 11:59 am    Post subject: [solution][snipplet] function update_twitter_status() using the API

Advertisement
Gravity Forms Plugin for WordPress
Back to top
ramon fincken
Site's programmer

Get a free globally recognized avatar
It's free!


Joined: 03 Aug 2007
Posts: 399
Location: A'dam/Diemen, The Netherlands

PostPosted: Sun Sep 05, 2010 2:45 pm    Post subject: Re: [solution][snipplet] function update_twitter_status() using the API Reply with quote

In addition/Update: due to the Twitter oauth's mechanism, the above function does not work anymore (for it will return an error code)

Haven't found a simple yet decent snipplet that actually works yet.
Back to top
View user's profile Send private message Visit poster's website
Post new topic   Reply to topic    Ramonfincken.com Forum Index -> PHP coding All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
General forums
The world of freelance
Programming
Other projects
Poll
I love gifts

Yes goodies and presents! [3]
No but I love polls ! [1]

Related google ads