I m just looking forward to tweet something directly from a webpage without using the tweet box. Of course, after authentication. 开发者_运维百科All i want is this. If the user is already logged in tweet directly if he clicks on the button. If not, provide an authentication screen and immediately after logging in tweet the text. And no use of tweet box. Any idea abt how this can be done? Thanks.
I have made a javascript function you can call onClick.. or just call the URL:
function tweet(url, text) {
url = encodeURIComponent(url);
text = encodeURIComponent(text);
window.open("http://twitter.com/intent/tweet?original_referer=" + url + "&text=" + text + "&url=" + url, "_blank");
}
I have used this on multiple project, easy to use, uses Twitter itself, simple and adds a short url to the message.
I am not 100% sure if this is what you are looking for, but can be handy.
Update
as @Curt commented below: Twitter is now only supporting oAuth so you might consider looking at the following answer related to oAuth Authorization with php: How can I use cURL (or any command line tool) to do an HTTP Post to Twitter, with OAuth authentication?
Yes!
Tweeter has an API you can do it through they are API or use something like this (using a server side script, PHP in this example):
Using the simple script below you, you can post updates to twitter. Please BE ADVISED: this script needs altered to run. As well as some extra code to add your desired functionality.
<?php
$username = 'myUserName';
$password = 'myPassword';
$status = urlencode(stripslashes(urldecode('This is a new Tweet!')));
if ($status) {
$tweetUrl = 'http://www.twitter.com/statuses/update.xml';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "$tweetUrl");
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$status");
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($curl);
$resultArray = curl_getinfo($curl);
if ($resultArray['http_code'] == 200)
echo 'Tweet Posted';
else
echo 'Could not post Tweet to Twitter right now. Try again later.';
curl_close($curl);
}
?>
Good Luck!
Source
精彩评论