Y
Y
Yuri Shchegolikhin2018-02-28 23:31:09
In contact with
Yuri Shchegolikhin, 2018-02-28 23:31:09

Community Suggested News API, why not working?

The script stopped working ((
Who can help?

<?php

$group_id = "102632763"; // ид группы

include dirname(__FILE__).'/cron/word_list.php';

$wallGet = api("/cron/wall.get",true,array(
  "owner_id"=>"-".$group_id,
  "filter"=>"suggests",
  "count"=>1,
));
//print_r($wallGet);

$items = $wallGet["response"]["items"];
for($i=0;$i<count($items);$i++){
  $item = $items[$i];
  $for_posting = false;
  $ch = check_spam($item["text"]);
  if($ch){
    echo "for del[ch]..\r\n";
    $posts_for_del[] = $item;
  }else{
    echo "not for del[ch]..\r\n";
    if($item["attachments"]){
      $photo_c = 0;
      $attach_err = false;
      for($x=0;$x<count($item["attachments"]);$x++){
        if($item["attachments"][$x]["type"] == "photo"){
          $photo_c++;
        }
        elseif($item["attachments"][$x]["type"] != "photo") $attach_err = true;
      }
      if($photo_c > $count_photo || $attach_err){
        $posts_for_del[] = $item;
      }else{
        $for_posting = true;
      }
    }else $for_posting = true;
    if($for_posting){
      # постинг с таймером
      echo "posting..\r\n";
      $publish_date = time() + $time_for_posting;
      $wallPost = api("wall.post",true,array(
        "owner_id"=>"-".$group_id,
        "post_id"=>$item["id"],
        "signed"=>1,
        "publish_date"=>$publish_date,
      ));
      print_r($wallPost);
      break;
      # / постинг с таймером
    }
  }
}

print_r("posts_for_del: ".count($posts_for_del));

for($i=0;$i<count($posts_for_del);$i++){
  $wallDel = api("wall.delete",true,array(
    "owner_id"=>"-".$group_id,
    "post_id"=>$posts_for_del[$i]["id"],
  ));
  print_r($wallDel);
  sleep(1);
}


function check_spam($text){
  global $spam_word;
  echo "\r\ncheck link..\r\n";
  $text = mb_strtolower(trim(strtolower($text)), "UTF-8");
  //if (preg_match("/(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/i", $text, $tt)) return true;
  if (preg_match("/(([\w\.\-\+]+:)\/{2}(([\w\d\.]+):([\w\d\.]+))[email protected]?(([a-zA-Z0-9\.\-_]+)(?::(\d{1,5}))?))?(\/(?:[a-zA-Z0-9\.\-\/\+\%]+)?)(?:\?([a-zA-Z0-9=%\-_\.\*&;]+))?(?:#([a-zA-Z0-9\-=,&%;\/\\\"'\?]+)?)?/i", $text)) return true;
  else{
    $text = strtr($text, array("!" => "","&" => "","?" => "","." => "","/" => ""));
    //echo $text."\r\n";
    echo "check spaming..\r\n";
    $spamtext = implode("|",$spam_word);
    if(preg_match("/".$spamtext."/", $text,$tt)){
      print_r($tt);
      return true;
    }
    else return false;
  }
}
function random($text){
  $random = mt_rand(0,count($text)-1); 
  return $text[$random];
}
function api($method, $token, $post = null) {
  global $access_token;
  if(!$post["v"]) $post["v"] = "5.45";
  if($token) $method .= "?access_token=".$access_token;
  $url = "https://api.vk.com/method/".$method;
  do{
    $while = false;
    $return = json_decode(curl($url, $post), true);
    if($return["error"]["error_code"] == 6){
      sleep(1);
      $while = true;
    }
  }while($while);
  return $return;
}
function curl($url, $post = null){
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417
  Firefox/3.0.3');
  if($post){
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  }
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false );
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );
  $response = curl_exec($ch);
  curl_close($ch);
  return $response;
}
?>

and second file
<?
$access_token = "мой токен"; // токен
$count_photo = ; // кол-во фотографий для допуска к постингу
$time_for_posting = ; // время для отложки

$spam_word = array(
"подпишись",
"вступи",
);
?>

Help me get back to work...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question