Örnek twitter uygulaması

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

?>  

Ben aşağıdaki çıktıyı almak

Error: 0 

Lütfen yardım edin.

2 Cevap

Bir hata olabilir ya da o yazı onu ortadan kaldırmak için unuttum, ama curl_close ($ ch) asla denir olabilir. Belki de ne tepki kadar tutan nedir? Eve gidince ben daha test edeceğiz.

libcurl documentation http_code yetmezliği (hiçbir sunucu yanıtı code) 0'a ayarlanır diyor. FALSE olup olmadığını response curl_getinfo çağırmadan önce kontrol ve çağrı curl_error olmalıdır. Ayrıca, responseInfo boş bir dizi saklamak hiçbir nokta yoktur. Sen yerine null ayarlayabilirsiniz.