1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Twitter profle imgs

Discussion in 'PHP & Perl' started by Saulyx, Dec 23, 2010.

  1. Saulyx

    Saulyx Junior Member

    Joined:
    Jan 10, 2010
    Messages:
    107
    Likes Received:
    5
    Evening everyone, I've coded this testing script, however everything works until I try to submit the image, then it tells me(twitter) that something went wrong, anyone could help me out?

    PHP:
    <?php
    require_once('scrape.php');


    $scrape = new Scrape();


    $scrape->fetch('http://twitter.com''profile_pic');

    $data = array('session[username_or_email]' => '***''session[password]' => '***');

    $data['authenticity_token'] = $scrape->fetchBetween('name="authenticity_token" type="hidden" value="','"',$scrape->result);

    $scrape->fetch('https://twitter.com/sessions''profile_pic'$data);

    $data['authenticity_token'] = $scrape->fetchBetween('name="authenticity_token" type="hidden" value="','"',$scrape->result);

    $scrape->fetch('http://twitter.com/settings/account''profile_pic'$data);

    $data['authenticity_token'] = $scrape->fetchBetween('name="authenticity_token" type="hidden" value="','"',$scrape->result);

    $scrape->fetch('http://twitter.com/settings/profile''profile_pic'$data);

    $data = array('_method' => 'put''user' => array('Name' => 'DanBlue''location' => 'UK''url' => 'http://google.com''description' => 'test123 blah blah'), 'commit' => 'Save''profile_image[uploaded_data]' => '@img.jpg');

    $data['authenticity_token'] = $scrape->fetchBetween('name="authenticity_token" type="hidden" value="','"',$scrape->result);

    $scrape->fetch('http://twitter.com/settings/profile''profile_pic'$data);



    echo 
    $scrape->result;


    ?>
    Scrape objec is a simple CURL, heres the fetch bit

    PHP:
    function fetch($url$username='',  $data=''$proxy=''){
            
            
            
    $ch curl_init();
            
            
    curl_setopt($chCURLOPT_URL$url);
            
            
    curl_setopt($chCURLOPT_HEADERfalse);
            
            if(isset(
    $proxy)) {        
            
    curl_setopt($chCURLOPT_PROXY$proxy); 
            
    curl_setopt($chCURLOPT_HTTPPROXYTUNNEL1);        
            }
            
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
            
    curl_setopt($chCURLOPT_FRESH_CONNECT,true);
            
            
    curl_setopt($chCURLOPT_USERAGENT"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); 
            
            
    curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
            
            
    curl_setopt($chCURLOPT_MAXREDIRS5);
            if(!empty(
    $username)) {
            
    curl_setopt($chCURLOPT_COOKIEFILE"cookie/{$username}.txt");
            
            
    curl_setopt($chCURLOPT_COOKIEJAR"cookie/{$username}.txt");
            }
            
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
            
            
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0); 
        
            
            if (
    is_array($data) && count($data)>0){
                
                
    curl_setopt($chCURLOPT_POSTtrue);
                
                
    $params http_build_query($data);
                
                
    curl_setopt($chCURLOPT_POSTFIELDS$params);
                
            }
                
            
            if (
    is_array($this->headers) && count($this->headers)>0){
                
                
    curl_setopt($chCURLOPT_HTTPHEADER$this->headers);
                
            }
            
            
            
    $this->result curl_exec($ch);
            
    $this->http_code curl_getinfo($chCURLINFO_HTTP_CODE);
            
    $this->error curl_error($ch);
            
            
    curl_close($ch);    
            
        }
    Would appreciate any help!
     
  2. Saulyx

    Saulyx Junior Member

    Joined:
    Jan 10, 2010
    Messages:
    107
    Likes Received:
    5
    seriously? No one can think of anything ?