|
|
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: 412 Location: A'dam/Diemen, The Netherlands
|
Posted: Mon May 24, 2010 11:59 am Post subject: [solution][snipplet] function update_twitter_status() using the API |
|
|
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 |
|
 |
Google adsense Advertisement
|
Posted: Mon May 24, 2010 11:59 am Post subject: [solution][snipplet] function update_twitter_status() using the API |
|
|
Advertisement
|
|
Back to top |
|
 |
GravityForms Advertisement
|
Posted: Mon May 24, 2010 11:59 am Post subject: [solution][snipplet] function update_twitter_status() using the API |
|
|
Advertisement
 |
|
Back to top |
|
 |
ramon fincken Site's programmer
 Get a free globally recognized avatar It's free!
Joined: 03 Aug 2007 Posts: 412 Location: A'dam/Diemen, The Netherlands
|
Posted: Sun Sep 05, 2010 2:45 pm Post subject: Re: [solution][snipplet] function update_twitter_status() using the API |
|
|
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 |
|
 |
|
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
|
|
|
|