Bruce
Bruce

Reputation: 35213

Sample twitter App

I am now running my code on a web hosting service http://xtreemhost.com/

<?php 
function updateTwitter($status)
{ 
    $username = 'xxxxxx'; 
    $password = 'xxxx';
    $url = 'http://api.twitter.com/1/statuses/update.xml'; 
    $postargs = 'status='.urlencode($status); 
    $responseInfo=array(); 
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    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) 
    $response = curl_exec($ch); 
    if($response === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    echo 'Operation completed without any errors<br/>';
}

    // 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']; 
    } 
curl_close($ch);
    }

updateTwitter("Just finished a sweet tutorial on http://brandontreb.com");

?>

I get the following error now

Curl error: Couldn't resolve host 'api.twitter.com' 
Error: 0

Please somebody solve my problem

Upvotes: 1

Views: 496

Answers (3)

manubkk
manubkk

Reputation: 1488

I came across the same error using xtreemhost.com's free hosting, I think they are blocking that domain but I was able to workaround by using twitter.com's IP address instead of the domain name.

Upvotes: 1

Jaysn
Jaysn

Reputation: 63

okay i think thats a free webhost

most of (or even every) Free Webspace Host disable the php network functions like curl or fsockopen/pfscokopen. thats because of the safe_mode that tries to fix security problems on shared hosts.

okay its architecturally incorrect to try to solve this problem at the PHP level, but since the alternatives at the web server and OS levels aren't very realistic, many people, especially Free Webspace Hosts, use safe mode for now.

Upvotes: 1

Quentin
Quentin

Reputation: 943143

You host's DNS appears to be broken. Call their technical support.

Upvotes: 1

Related Questions