2010-03-26 102 views
1

我現在運行我的代碼的Web託管服務上http://xtreemhost.com/樣品Twitter的應用程序

<?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"); 

?> 

我碰到下面的錯誤,現在

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

請人解決我的問題

+0

我錯過了什麼,或者是api.twitter.com不在您的腳本中? – 2010-03-26 10:51:12

+0

不,你不會錯過任何東西...我的壞..我現在編輯了代碼 – Bruce 2010-03-26 11:24:46

+0

你有沒有嘗試過其他一些網址,看看你是否總是得到相同的錯誤? – DisgruntledGoat 2010-03-26 11:41:33

回答

1

您主機的DNS似乎被打破了。呼叫他們的技術支持。

1

好吧,我覺得這就是一個免費的虛擬主機提供商

大部分(或者甚至每)免費網絡空間的主機禁用PHP網絡功能,如curlfsockopen/pfscokopen。這是因爲safe_mode試圖解決共享主機上的安全問題。

好吧,它的體系結構不正確,試圖解決PHP級別的這個問題,但由於Web服務器和操作系統級別的替代方案不太現實,許多人(尤其是免費Webspace主機)現在都使用安全模式。

+0

是的,它是一個免費的網絡主機...但捲曲啓用...我現在該怎麼辦? – Bruce 2010-03-26 11:25:58