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?
Scrape objec is a simple CURL, heres the fetch bit
Would appreciate any help!
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;
?>
PHP:
function fetch($url, $username='', $data='', $proxy=''){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
if(isset($proxy)) {
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT,true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
if(!empty($username)) {
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie/{$username}.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie/{$username}.txt");
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
if (is_array($data) && count($data)>0){
curl_setopt($ch, CURLOPT_POST, true);
$params = http_build_query($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
}
if (is_array($this->headers) && count($this->headers)>0){
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
}
$this->result = curl_exec($ch);
$this->http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->error = curl_error($ch);
curl_close($ch);
}