又更新了一下,使用m.renren.com进行状态发布
脚本名称正式定为twitter2renren.php
使用方法详见这篇日志
代码:
< ?php // //twitter2renren.php //By @yegle, yegle.net //Licensed under CC by-nc-sa //Version:20100828 // $file = '/home/yegle/.twitter2renren'; $cookie_file = '/home/yegle/.twitter2renren.cookie'; $twitter_username = ''; $twitter_pwd = ''; $hashtag = ''; $renren_username = ''; $renren_password = ''; //配置完毕,请停止编辑文件! if(file_exists($file)){ $lastid = intval(file_get_contents($file)); } else{ touch($file); $lastid = 0; } $timeline_url = 'http://'.$twitter_username.':'.$twitter_pwd.'@twitter.com/statuses/user_timeline.rss?count=200'; if($lastid!==0) $timeline_url.='&since_id='.$lastid; $timeline = file_get_contents($timeline_url); $obj = simplexml_load_string($timeline); $items = $obj->channel->item; if(empty($items)){ echo "no newer tweet\n"; exit(); } if(sizeof($items)==1){ $new_id = preg_replace('/.*\/([0-9]*)$/','$1',strval($items->link)); } else{ $new_id = preg_replace('/.*\/([0-9]*)$/','$1',strval($items[0]->link)); } if($new_id == ''){ echo "error\n"; exit(); } file_put_contents($file,$new_id); $post_arr = array(); foreach($items as $tweet){ $text = substr($tweet->title,strlen($twitter_username)+2); if(strpos($text,'@')!==0 && ( empty($hashtag) || strpos($text,$hashtag)!==FALSE)){ $text = str_replace("RT: @","转自",$text); $post_arr[] = $text.' [twitter]'; } } if(empty($post_arr)){ echo "no need.\n"; exit(); } $post_arr = array_reverse($post_arr); foreach($post_arr as $item){ $post = 'sour=home&status='.urlencode($item).'&update=发布'; $renren_login = "http://3g.renren.com/login.do?fx=0&autoLogin=true"; $ch = curl_init(); curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file); curl_setopt($ch,CURLOPT_URL,$renren_login); curl_setopt($ch,CURLOPT_POST,TRUE); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE); curl_setopt($ch,CURLOPT_POSTFIELDS,'email='.$renren_username.'&password='.$renren_password.'&login=登录'); curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); #curl_setopt($ch,CURLOPT_VERBOSE,TRUE); $str = curl_exec($ch); curl_close($ch); $pattern = '/action="([^"]*)"/'; preg_match($pattern,$str,$matches); $ch = curl_init($matches[1]); curl_setopt($ch,CURLOPT_POST,TRUE); curl_setopt($ch,CURLOPT_POSTFIELDS,$post); curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file); //curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE); //curl_setopt($ch,CURLOPT_REFERER,'http://status.renren.com/ajaxproxy.htm'); $ret = curl_exec($ch); curl_close($ch); } ?>

近期评论