我正在使用curl登录tumblr进行某些操作。我没有使用tumblr api,因为还有其他一些限制。
如其他一些帖子所述。我使用curl_init,然后多个curl_exec并关闭。但它似乎没有用。 $ result1显示我已成功登录。但是$ result2是空的。
$request_data = http_build_query(
array(
'email' => $tumblr_email,
'password' => $tumblr_password,
)
);
$c1 = curl_init('http://www.tumblr.com/login');
curl_setopt($c1, CURLOPT_POST, true);
curl_setopt($c1, CURLOPT_POSTFIELDS, $request_data);
curl_setopt($c1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c1, CURL_COOKIEFILE, '');
$result1 = curl_exec($c1);
curl_setopt($c1, CURLOPT_URL, 'http://www.tumblr.com/likes/page/2');
$result2 = curl_exec($c1);
curl_close($c1);
答案 0 :(得分:1)
$request_data = http_build_query(
array(
'email' => $tumblr_email,
'password' => $tumblr_password,
)
);
$c1 = curl_init('http://www.tumblr.com/login');
curl_setopt($c1, CURLOPT_POST, true);
curl_setopt($c1, CURLOPT_POSTFIELDS, $request_data);
curl_setopt($c1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c1, CURL_COOKIEFILE, 'somefilename1.txt');
curl_setopt($c1,CURLOPT_COOKIEJAR, 'somefilename1.txt');
curl_setopt($c1,CURLOPT_FRESH_CONNECT,true);//No caching
curl_setopt($c1,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($c1,CURLOPT_MAXREDIRS,1);
$result1 = curl_exec($c1);
curl_setopt($c1, CURLOPT_URL, 'http://www.tumblr.com/likes/page/2');
curl_setopt($c1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c1, CURL_COOKIEFILE, 'somefilename1.txt');
curl_setopt($c1,CURLOPT_COOKIEJAR, 'somefilename1.txt');
curl_setopt($c1,CURLOPT_FRESH_CONNECT,true);//No caching
curl_setopt($c1,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($c1,CURLOPT_MAXREDIRS,1);
$result2 = curl_exec($c1);
curl_close($c1);
检查一下,它会起作用,实际上你应该指定一些文件名来存储来自网站的cookie,它可能用于某些身份验证