Jump to content

Posting to Twitter using PHP snippet


fumbler

Recommended Posts

I found the following snippet today. I'm new to PHP and am trying to use this snippet to add a text area to a page on my site that posts to Twitter whatever I enter into the text area. This code seems perfect and it works, but lacks the actual html text area where I would enter the text to post. (instead it just has a default message on the $message = line) Where or how in your opinion would I enter that text area in this code below?

 

<?php

// Set username and password

$username = 'username';

$password = 'password';

// The message you want to send

$message = 'is twittering from php using curl';

// The twitter API address

$url = 'http://twitter.com/statuses/update.xml';

// Alternative JSON version

// $url = 'http://twitter.com/statuses/update.json';

// Set up and execute the curl process

$curl_handle = curl_init();

curl_setopt($curl_handle, CURLOPT_URL, "$url");

curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl_handle, CURLOPT_POST, 1);

curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");

curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");

$buffer = curl_exec($curl_handle);

curl_close($curl_handle);

// check for success or failure

if (empty($buffer)) {

    echo 'message';

} else {

    echo 'success';

}

?>

Link to comment
https://forums.phpfreaks.com/topic/131724-posting-to-twitter-using-php-snippet/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.