matt
matt

Reputation: 11

Connect to Twitpic API using PHP

I am using the Twitpic API for an application. I am a bit stuck because I can't seem to find were the error is. This piece of code all the documentation I read says it's correct. Help would be appreciated. Thanks!

function do_twitpic() 
{           
    $media = 'http://image-to-upload.jpg'; 
    $username = $_POST['username'];
    $password = $_POST['password'];

    $postfields = array(); 
    $postfields['username'] = $username; 
    $postfields['password'] = $password;  
    $postfields['media'] = "@".$media;

    $twitter_url = 'http://twitpic.com/api/upload'; 
    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2); 
    curl_setopt($curl, CURLOPT_HEADER, false); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1); 
    curl_setopt($curl, CURLOPT_URL, $twitter_url); 
    curl_setopt($curl, CURLOPT_POST, 3); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields); 
    $result = curl_exec($curl); 
    curl_close($curl); 
    $login_xml = new SimpleXMLElement($result); 
    if (isset($login_xml->error)) { 
        print_r($login_xml); 
    } else { 
        print_r($login_xml); 
    }   
}

Thanks alot!

Upvotes: 1

Views: 855

Answers (2)

Gary Brandingfarm
Gary Brandingfarm

Reputation: 1

The @ in front of the 'real path' of the images, not the public URL, converts the image to binary data dynamically.

Upvotes: 0

trashcan
trashcan

Reputation: 1

According to this page $media needs to be binary encoded data of the image, not the URL to it. http://www.twitpic.com/api.do#upload

Upvotes: 0

Related Questions