P
P
Pavel Chuev2016-04-08 22:07:01
PHP
Pavel Chuev, 2016-04-08 22:07:01

Why can't I complete the request?

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$token = '';
$wall = file_get_contents("http://api.vk.com/method/wall.get?v=5.7&filter=all&domain=achan&count=1000");
$wall = json_decode($wall);
$wall = $wall->response->items;
for ($i = 0; $i < count($wall); $i++) {
$x = $wall[$i]->post_type;
if($x !== 'post'){
$date1 = new DateTime("now");
$date2 = new DateTime("@".$wall[$i]->date);
$interval = $date2->diff($date1);
$day = $interval->format("%d");
if($day == '1'){
while ($gid = '-100562658')
{
$statusSet = curl('https://api.vk.com/method/wall.delete?v=5.7&owner_id'.$gid.'&access_token='.$token.'&post_id='.$wall[$i]->id);
}
function curl( $url ){
    $ch = curl_init( $url );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    $response = curl_exec( $ch );
    curl_close( $ch );
    return $response;
}
}
}}
?>

In general, I wrote a code that should delete reposts on the wall after 24 hours. Everything seems to be fine, but requests are not executed. What's the matter? I rarely turn to php and I don't know everything about curl. So don't go straight to the documentation.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
OVK2015, 2016-04-09
@AllDecay

<?php
$token = '';
$wall = file_get_contents("http://api.vk.com/method/wall.get?v=5.7&filter=all&domain=achan&count=1000");
$postAmount = count($wall->response->items);

$counter = 1;
$currentTime = new DateTime("now");
foreach($wall->response->items as $currentItem)
{	
  $postDate = new DateTime(date("Y-m-d H:i:s", $currentItem->date));		
  $interval = $currentTime->diff($postDate);	
  if($interval->d >= 1)
  {
    echo $counter.". Нужно удалить\t".$postDate->format("Y-m-d H:i:s")."\n";
  }	
  else
  {
    echo $counter.". Пока оставляем\t".$postDate->format("Y-m-d H:i:s")."\n";
  }
  $counter++;	
}
?>

Candidates for deletion selects correctly.

I
Immortal_pony, 2016-04-08
@Immortal_pony

The symbol "=" is missing in the link for one of the parameters:
&owner_id'.$gid.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question