How to post other user status with their twitter username / Password available


#1

Hi,

We are developing an site where different users can create their Top 10 movies list.
They can share it on FB and tweet the URL of the created top 10 in twitter.

Please let me know how to post the update of an user with their username/password available.

I tried some code like this :

// set username and password
$username = 'your-username-here';
$password = 'your-password-here';
// add the message you want to send
$message = 'is tweeting using php and curl';
// set the twitter API address
$url = 'https://api.twitter.com/1/statuses/update.json';
// setup a curl process
$curl_handle = curl_init();
// set the url of the curl process
curl_setopt($curl_handle, CURLOPT_URL, "$url");
// saves the return value as a string value instead of outputting to browser
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
// to send data as $_POST fields as required by the twitter API
curl_setopt($curl_handle, CURLOPT_POST, 1);
// set the post fields
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
// set the username and password for the connection
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
// exectute the curl request and save output as $buffer variable
$buffer = curl_exec($curl_handle);
// close the curl connection
curl_close($curl_handle);
// decode json output into array
$json_output = json_decode($buffer, true);
print_r($json_output);
// check for success or failure
if (isset($json_output['error'])) {
    // tweet not successful, display error
    echo "Fail: ".$json_output['error'];
}
else {
    // tweet is successful
    //$json_output contains return variables for this tweet
    echo "Success";
}

Any help would be greatly appreciated.

Thanks,
Mugunthan,


#2

This code is no longer functional as “basic auth” (auth by username and password) isn’t supported by the API. You’ll need to use OAuth 1.0A to work with the API and post tweets on behalf of users who have authorized your application to work on their behalf.


#3