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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.