or_die, the error logs have disappeared, but nothing is published on the page ... After the script is executed, the message "Update" is displayed. on the file of cookies and tweets are the rights 777, on the script 644 itself, and everything is recorded in the file of cookies and in the file of tweets after the execution of the script.

There is a script, with it you can publish twitter statuses in VKontakte automatically, but I would like to publish not on the profile wall, but in a group or an official page, for example: http://vkontakte.ru/of_stranica , how should the script be changed? PS Here is the script itself:

 <?php /* tvkontakte 0.1i vkontakte.ru status updater from twitter made by Vladimir Smirnoff http://orl.sumy.ua mail@smirnoff.sumy.ua improved by Kichrum http://Kichrum.org.ua */ # Конфигурация - ОТРЕДАКТИРУЙ! define ('TWITTER_USERNAME','MyLogin'); // MyLogin заменить на свой Логин в Twitter define ('VKONTAKTE_LOGIN','user@mail.ua'); // user@mail.ua заменить на свой E-mail на Vkontakte.ru define ('VKONTAKTE_PASSWORD','12345'); // gfhjkm заменить на свой Пароль на Vkontakte.ru define ('PREPEND_WORD','Twitter.com/user'); // Twitter.com/user заменить на Слово, которое будет перед статусом: максимальная длинна: 20 символов с пробелами = 160 во vkontakte - 140 в twitter # Конфигурация выполнена. # Дальше можно не читать :) # Объявляем Дуровский UserAPI class vkuserapi { private $curlh = null; public $uid = null; private $sid = null; public function __construct ($login,$password) { $this->curlh = curl_init(); $request = 'http://login.userapi.com/auth?site=2&login=force&pass='.urlencode($password).'&email='.urlencode($login); curl_setopt($this->curlh, CURLOPT_URL,$request); curl_setopt($this->curlh, CURLOPT_FAILONERROR, true); curl_setopt($this->curlh, CURLOPT_FOLLOWLOCATION, false); curl_setopt($this->curlh, CURLOPT_RETURNTRANSFER, true); curl_setopt($this->curlh, CURLOPT_POST, false); curl_setopt($this->curlh, CURLOPT_HEADER, true); $auth_result = curl_exec($this->curlh); if (preg_match("/remixmid=(\d+)/", $auth_result, $matches)) $this->uid = $matches[1]; if (preg_match("/.*;sid=(\w*)/", $auth_result, $matches)) $this->sid = $matches[1]; } public function call ($func,$params) { curl_setopt($this->curlh, CURLOPT_HEADER, false); $request = 'http://userapi.com/data?act='.$func.'&'.http_build_query ($params).'&sid='.$this->sid; curl_setopt($this->curlh, CURLOPT_URL,$request); $result = curl_exec($this->curlh); return json_decode($result); } public function __destruct () { $request = 'http://login.userapi.com/auth?login=logout&site=2&sid='.$this->sid; curl_setopt($this->curlh, CURLOPT_URL,$request); curl_exec($this->curlh); curl_close ($this->curlh); } } # Берем статус со своей RSS-ленты на Twitter.com $rss = simplexml_load_file('http://twitter.com/statuses/user_timeline/'.TWITTER_USERNAME.'.rss'); # Убираем лишнюю информацию foreach ($rss->channel->item as $status) { if (strpos($status->title,'@')) continue; // Фильтр реплаев в Twitter $last_status_twitter = str_replace (TWITTER_USERNAME.': ','',$status->title); break; } # Читаем последний обновлённый статус из файла vtweet.txt $f=fopen(dirname(__FILE__).'/vtweet.txt','r'); $last_status_vkontakte = fread($f,512); fclose($f); # Если последний статус ещё не опубликован во В Контакте, публикуем и помечаем его как обновлённый if (($last_status_vkontakte != $last_status_twitter) && ($last_status_twitter != NULL)) { $vkontakte = new vkuserapi (VKONTAKTE_LOGIN,VKONTAKTE_PASSWORD); // Логинимся $vkontakte->call ('set_activity',array('ts'=>time(),'text'=>PREPEND_WORD.$last_status_twitter)); // Обновляем статус unset ($vkontakte); // Выходим из Vkontakte.ru $f=fopen(dirname(__FILE__).'/vtweet.txt','w'); fwrite($f,$last_status_twitter); // "Помечаем" статус как уже обновлённый fclose($f); echo 'Updatetd.'; } else echo 'No update needed.'; // Если последний уже помечен, выводим внутреннюю ошибку. # Завершаем работу программы. ?> 

or_die, this script will be used both on a VPS and on a regular hosting. (I had to edit the message because I can’t add comments anymore)

  • Then I don’t know what's wrong. Everything works smoothly for me even with open_basedir - or_die
  • or_die, if not difficult, write me: bing-pochta@live.ru I would like to understand what the problem is ... - nick777

1 answer 1

Rewrote, it seems to work :)

 <?php ################## $vk_login = 'mail@mail.ru'; $vk_password = 'vkontakte pass'; $vk_page = 'vk puplic page'; $tw_login = 'tw login'; ################## $cookie_file = 'cookies.txt'; $tweet_file = 'vtweet.txt'; $mode = 1; // 1 - парсим только последнее сообщение 0 - все сообщения ################## VK_Login($vk_login, $vk_password); $f=fopen(dirname(__FILE__).'/'.$tweet_file,'r'); $rss = simplexml_load_file('http://twitter.com/statuses/user_timeline/'.$tw_login.'.rss'); # Убираем лишнюю информацию foreach ($rss->channel->item as $status) { if (strpos($status->title,'@')) continue; // Фильтр реплаев в Twitter $last_status_twitter = str_replace ($tw_login.': ','',$status->title); $last_status_vkontakte = fread($f,512); if (($last_status_vkontakte != $last_status_twitter) && ($last_status_twitter != NULL)) { VK_Page_Sending($last_status_twitter); $f=fopen(dirname(__FILE__).'/'.$tweet_file,'w'); fwrite($f,$last_status_twitter); echo ($mode == 1) ? "Update" : ""; } else { echo ($mode == 1) ? 'No update needed.' : ""; } if($mode == 1) break; } fclose($f); function VK_Login($vk_login,$vk_password) { global $cookie_file; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, "http://vkontakte.ru/login.php?m=1&email={$vk_login}&pass={$vk_password}"); curl_setopt ($ch, CURLOPT_USERAGENT, "Opera/9.64 (Windows NT 5.1; U; ru) Presto/2.1.1"); $headers = array( 'Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1', 'Accept-Language: ru-RU,ru;q=0.9,en;q=0.8', 'Content-Type: application/x-www-form-urlencoded', 'Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1', 'Accept-Encoding: deflate', 'Cookie2: $Version=1', 'Connection: Keep-Alive, TE', 'TE: deflate, gzip, chunked, identity, trailers'); curl_setopt($ch, CURLOPT_HTTPHEADER,$headers); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch,CURLOPT_ENCODING , "gzip"); curl_exec($ch); curl_close($ch); } function VK_Page_Sending($message) { global $vk_page, $cookie_file; static $hash, $public_id; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); if(!isset($hash) && !isset($public_id)) { curl_setopt($ch, CURLOPT_URL, 'http://vkontakte.ru/'.$vk_page); $answer = curl_exec($ch); preg_match('#"post_hash":"(.*?)"#',$answer,$hash_array); preg_match('#"public_id":(\d+)#i',$answer,$public_id_array); $hash = $hash_array[1]; $public_id = $public_id_array[1]; } curl_setopt($ch, CURLOPT_URL, 'http://vkontakte.ru/al_wall.php'); $post_send = array( 'act' => 'post', 'al' => 1, 'hash' => $hash, 'message' => $message, 'to_id' => '-'.$public_id, 'type' => 'all' ); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_send)); curl_exec($ch); curl_close($ch); } ?> 
  • Writes Updatetd, but the publication does not happen, removed from the line: <code> curl_setopt ($ ch, CURLOPT_URL, ' vkontakte.ru/public'..vk_page_id ); <code> public, since I have a page without this prefix, I removed it - nothing has changed. But infa from the feed is recorded in vtweet.txt. What is the problem? - nick777
  • It seems corrected - or_die
  • or_die, everything is still, here is the error log: <code> [Sun Jul 17 20:38:26 2011] [error] [client my_ip] PHP Warning: curl_setopt () [<a href = 'function.curl-setopt' > function.curl-setopt </a>]: CURLOPT_FOLLOWLOCATION can’t be activated when safe_mode is enabled or an open_basedir is set in /var/www/user/data/www/site.ru/test.php on line 44 </ code > Line 44: <code> curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true); </ code> As I understand it, you should turn off safe_mode and open_basedir in php.ini, but you shouldn’t turn off open_basedir for any security reasons. exits? - nick777 4:44 pm
  • 1 Turn off open_basedir 2 Catch the Location headers and cut the address from there, then go through them 3 Take a class, for example Snoopy - or_die
  • I wrote a function here: zalil.ru/31433124 * In the file with a triple- dot I marked the repeating code, I changed only the function Sending ($ message). The script started to give out 500 errors, apparently, did something wrong, but this is most likely due to the fact that I got acquainted with the snoopy class only today. - nick777 pm