madblacker
Regular Member
- Nov 2, 2009
- 291
- 35
I've given up on using imacros and am now learning Curl, I already know PHP fairly well at this point, I'm testing this to login to twitter and make a tweet post, I know this can be done via the API but its more that I want to be able to automate any web tasks (so this is helping me learn) and its bothering me that I can't get this to work and also I want to register accounts via curl on twitter which can't be done via the api.
One thing that I found weird is that I have to post the login POST as the url for it to work.. when I watch the output of the 2nd curl call (where it attempts to post the tweet) it shows the page as having the tweet entered in the input box but it doesn't go through and actually make the tweet.. I've already spent countless hours trying to figure this out.. I got the POST calls from wireshark, using the full TCP package (or whatever its called)... I would greatly appreciate any advice
<CODE>
<?php
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, "C:/Users/a/work-current/cookies/my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "C:/Users/a/work-current/cookies/my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0) ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0) ;
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3)
//Gecko/20100401 Firefox/3.6.3");
curl_exec($ch);
#### set curl login post string
$test_username = 'myuseraccnt';
$test_password = 'mypassword';
$curl_login_post = "https://twitter.com/sessions?authenticity_token=c3884f449f86484198b26fc0c8adc79275ad4552&authenticity_token=c3884f449f86484198b26fc0c8adc79275ad4552&return_to_ssl=false&session[username_or_email]=". $test_username . "&session[password]=". $test_password . "&commit=Sign+In" ;
// login via curl
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_login_post);
curl_setopt($ch, CURLOPT_URL, $curl_login_post);
curl_exec($ch);
// post tweet via curl
$test_tweet = "authenticity_token=c3884f449f86484198b26fc0c8adc79275ad4552&status=teeessssssstttttttwwwwwwweeeeetttttttt%0A&twttr=true&return_rendered_status=true&lat=&lon=&place_id=&display_coordinates=false" ;
curl_setopt($ch, CURLOPT_POST, 'TRUE');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_REFERER, 'http://twitter.com');
curl_setopt($ch, CURLOPT_POSTFIELDS, $test_tweet);
curl_setopt($ch, CURLOPT_URL, 'http://twitter.com' );
curl_exec($ch);
?>
</CODE>
One thing that I found weird is that I have to post the login POST as the url for it to work.. when I watch the output of the 2nd curl call (where it attempts to post the tweet) it shows the page as having the tweet entered in the input box but it doesn't go through and actually make the tweet.. I've already spent countless hours trying to figure this out.. I got the POST calls from wireshark, using the full TCP package (or whatever its called)... I would greatly appreciate any advice
<CODE>
<?php
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, "C:/Users/a/work-current/cookies/my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "C:/Users/a/work-current/cookies/my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0) ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0) ;
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3)
//Gecko/20100401 Firefox/3.6.3");
curl_exec($ch);
#### set curl login post string
$test_username = 'myuseraccnt';
$test_password = 'mypassword';
$curl_login_post = "https://twitter.com/sessions?authenticity_token=c3884f449f86484198b26fc0c8adc79275ad4552&authenticity_token=c3884f449f86484198b26fc0c8adc79275ad4552&return_to_ssl=false&session[username_or_email]=". $test_username . "&session[password]=". $test_password . "&commit=Sign+In" ;
// login via curl
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_login_post);
curl_setopt($ch, CURLOPT_URL, $curl_login_post);
curl_exec($ch);
// post tweet via curl
$test_tweet = "authenticity_token=c3884f449f86484198b26fc0c8adc79275ad4552&status=teeessssssstttttttwwwwwwweeeeetttttttt%0A&twttr=true&return_rendered_status=true&lat=&lon=&place_id=&display_coordinates=false" ;
curl_setopt($ch, CURLOPT_POST, 'TRUE');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_REFERER, 'http://twitter.com');
curl_setopt($ch, CURLOPT_POSTFIELDS, $test_tweet);
curl_setopt($ch, CURLOPT_URL, 'http://twitter.com' );
curl_exec($ch);
?>
</CODE>
Last edited: