N
N
Nesquix2018-12-03 12:49:47
PHP
Nesquix, 2018-12-03 12:49:47

Why does the VK autostatus not work?

Hello. There is an autostatus code with a reverse timer to a number. The problem is that for some reason it doesn't work.
Can you suggest why?

<?php 
$access_token = 'Токен';
date_default_timezone_set ('Europe/Moscow');
$hour = ceil((mktime(0,0,0, 29, 12, 2018) - time())/57400);
$time = date("H:i");
$Date = date("d.m");
$getLikes = curl('https://api.vk.com/method/photos.get?album_id=profile&rev=1&extended=1&count=1&access_token='.$access_token.'&v=3.0');
$getLikesJson = json_decode($getLikes,1);
$likes = $getLikesJson['response']['0']['likes']['count'];
switch (substr($hour, -1)) {
  case 1: $prnt='день';
  case 2: case 3: case 4: $prnt='дня';
  break;
  default:$prnt='день';
}
$status = 'До важного события осталось:'.$hour.' '.$prnt.'  ';
$statusSet = curl('https://api.vk.com/method/status.set?text='.urlencode($status).'&access_token='.$access_token);
$jsonS = json_decode($statusSet,1);
if ($jsonS['response']=='1'){
addlog('OK');
}
else{
addlog('ERROR: '.$jsonS['error']['error_msg']);
}

function addlog($logtext){
$fp = fopen( './log.txt', 'a' );
fwrite( $fp, '['.date( 'd.m.Y H:i:s', time() ).'] '.$logtext.PHP_EOL);
}

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;
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bublik1337, 2018-12-03
@Nesquix

The version in $statusSet is not specified, so the script is not executed

<?php 
$access_token = '';
date_default_timezone_set ('Europe/Moscow');
$hour = ceil((mktime(0,0,0, 29, 12, 2018) - time())/57400);
$time = date("H:i");
$Date = date("d.m");
echo $getLikes = curl('https://api.vk.com/method/photos.get?album_id=profile&rev=1&extended=1&count=1&access_token='.$access_token.'&v=3.0');
$getLikesJson = json_decode($getLikes,1);
$likes = $getLikesJson['response']['0']['likes']['count'];
switch (substr($hour, -1)) {
  case 1: $prnt='день';
  case 2: case 3: case 4: $prnt='дня';
  break;
  default:$prnt='день';
}
$status = 'До важного события осталось:'.$hour.' '.$prnt.'  ';
echo$statusSet = curl('https://api.vk.com/method/status.set?text='.urlencode($status).'&v=3.0&access_token='.$access_token);
$jsonS = json_decode($statusSet,1);
if ($jsonS['response']=='1'){
addlog('OK');
}
else{
addlog('ERROR: '.$jsonS['error']['error_msg']);
}

function addlog($logtext){
$fp = fopen( './log.txt', 'a' );
fwrite( $fp, '['.date( 'd.m.Y H:i:s', time() ).'] '.$logtext.PHP_EOL);
}

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;
}
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question