脚本宝典收集整理的这篇文章主要介绍了php – 用curl登录twitter,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP $ch = curl_init($sTarget); curl_setopt($ch,CURLOPT_HEADER,false); curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_POSTFIELDS,$sPost); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,CURLOPT_RETURNtransfer,CURLOPT_SSL_VERIFYPEER,CURLOPT_SSL_VERIFYHOST,CURLOPT_COOKIESESSION,CURLOPT_cookiejar,$_CKS); curl_setopt($ch,CURLOPT_COOKIEFILE,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']); curl_setopt($ch,CURLOPT_HTTPHEADER,array("Content-type: multipart/form-data")); curl_setopt($ch,CURLOPT_REFERER,"https://twitter.COM"); ?>
$sPost看起来像这样:
代码首先获取登录表单字段,以便post变量具有正确的值(auth令牌).我只是尝试了一切,是的,我知道这有一个api但我宁愿找到如何为学习而做手册.
提前致谢.
<?PHP # First call gets hidden form field authenticity_token # and session cookie $ch = curl_init(); $sTarget = "https://twitter.com/"; curl_setopt($ch,CURLOPT_URL,$sTarget); curl_setopt($ch,true); curl_setopt($ch,false); curl_setopt($ch,$_SERVER['HTTP_USER_AGENT']); curl_setopt($ch,"/tmp/cookie.txt"); curl_setopt($ch,"https://twitter.com/"); $htML = curl_exec($ch); # parse authenticity_token out of html response PReg_match('/<input type="hidden" value="([a-zA-Z0-9]*)" name="authenticity_token"\/>/',$html,$match); $authenticity_token = $match[1]; $username = "your@email.com"; $password = "password"; # set post data $sPost = "session[username_or_email]=$username&session[password]=$password&return_to_ssl=true&scribe_LOG=&redirect_after_login=%2F&authenticity_token=$authenticity_token"; # second call is a post and performs login $sTarget = "https://twitter.com/sessions"; curl_setopt($ch,$sPost); curl_setopt($ch,array("Content-type: application/x-www-form-urlencoded")); # display server response curl_exec($ch); curl_close($ch); ?>
PS:很抱歉没有第一次正确阅读你的帖子.
以上是脚本宝典为你收集整理的php – 用curl登录twitter全部内容,希望文章能够帮你解决php – 用curl登录twitter所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。