<?php
function updateTwitter($status)
{
// Twitter login information
$username = 'xxxxx';
$password = 'xxxxxx';
// The url of the update function
$url = 'http://twitter.com/statuses/update.xml';
// Arguments we are posting to Twitter
$postargs = 'status='.urlencode($status);
// Will store the response we get from Twitter
$responseInfo=array();
// Initialize CURL
$ch = curl_init($url);
// Tell CURL we are doing a POST
curl_setopt ($ch, CURLOPT_POST, true);
// Give CURL the arguments in the POST
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);
// Set the username and password in the CURL call
curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);
// Set some cur flags (not too important)
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// execute the CURL call
$response = curl_exec($ch);
// Get information about the response
$responseInfo=curl_getinfo($ch);
// Close the CURL connection curl_close($ch);
// Make sure we received a response from Twitter
if(intval($responseInfo['http_code'])==200){
// Display the response from Twitter
echo $response;
}else{
// Something went wrong
echo "Error: " . $responseInfo['http_code'];
}
}
updateTwitter("Just finished a sweet tutorial on http://brandontreb.com");
?>
我得到以下输出样品Twitter应用
Error: 0
请帮助。
响应是假,我碰到下面的错误; curl错误:无法连接到主机 – Bruce 2010-03-25 07:10:34
我再添加一行代码 curl_setopt($ ch,CURLOPT_PROXY,“localhost:80”); 现在,我得到错误:404 – Bruce 2010-03-25 07:51:47
我删除了这句话,现在使用的网络托管服务来运行我的代码,我收到以下错误卷曲错误:无法解析主机“api.twitter.com”错误:0 – Bruce 2010-03-26 09:37:32