自动推特到推特

时间:2011-01-22 09:08:22

标签: codeigniter twitter

我使用了followint curl功能从我的codeigniter页面自动发送推文,但我得到的是HTTP响应代码401(未经授权)。

代码是:

var $accounts_table = 'accounts';
var $update_url = 'http://twitter.com/statuses/update.xml';

function update_status($username, $password, $message)
{
    $ch = curl_init($this->update_url);

    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'status='.urlencode($message));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, $username .':'.$password);

    curl_exec($ch);

    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    echo $httpcode;
    // if we were successfull we need to update our last_message
    if ($httpcode == '200')
    {
        $this->db->where('active', '1');
        $this->db->update($this->accounts_table, array('last_message' => $message));

        return TRUE;
    }

    else
    {
        return FALSE;
    }
}

请帮助我解决这个问题。

提前致谢。

1 个答案:

答案 0 :(得分:1)

AFAIK,Twitter已经转移到OAuth.ie,没有更多的基本身份验证 了解有关OAuth here的更多信息 OAuth支持libraries