E
E
Eugene Dragan2021-11-30 01:49:50
PHP
Eugene Dragan, 2021-11-30 01:49:50

Error 100 in VK ShortLink API how to fix?

When shortening links, I get an error 100 in response - one of the required parameters was not passed or is incorrect.

Links shortens, but not all and selectively, if you re-insert those links that are not shortened, shortens without problems.
Did everything according to the documentation. What is the problem I do not understand. Method: Utils.

<?php
$token = '73dda6c273dda6c273dda6c20973a4d96a773dd73dda6c2128ea028410e86eb57dabafb';
if(isset($_POST['links'])){
    if(empty($_POST['links'])){
        $result = '';
    }
    else{
        $links = explode(PHP_EOL, $_POST['links']);
        $links = array_unique($links, SORT_REGULAR);
        $arr = array();
        for($i = 0; $i < count($links); ++$i) {
            if(empty($_POST['private'])) {
                $query = file_get_contents("https://api.vk.com/method/utils.getShortLink?url=".urlencode($links[$i])."&access_token=".$token."&v=5.131");
            }
            else {
                $query = file_get_contents("https://api.vk.com/method/utils.getShortLink?url=".urlencode($links[$i])."&private=1&access_token=".$token."&v=5.131");
            }
            $result = json_decode($query,true);
            if($result['error']['error_code']){
                $result = '';
            }
            else{
                array_push($arr, $result['response']['short_url']);
            }
            $arr = array_unique($arr, SORT_REGULAR);
            $send = implode(PHP_EOL, $arr);
        }
    }
}
?>


Has anyone come across this error or figured it out, please help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Forever Extreme, 2021-11-30
@dragan2011

I also stuck with VK for a long time. For example, when uploading photos, the documentation is not quite correctly written. I had to smoke their SDK and a couple more projects on gihab. Try guzzle. This makes it easier to collect data for the form.
Plus, the documentation shows an example of how to transfer data. It is possible that VK simply does not see your parameters

$user_id = 210700286;
$request_params = array(
'user_id' => $user_id,
'fields' => 'bdate',
'v' => '5.52',
'access_token' => '533bacf01e11f55b536a565b57531ac114461ae8736d6506a3'
);
$get_params = http_build_query($request_params);
$result = json_decode(file_get_contents('https://api.vk.com/method/users.get?'. $get_params));
echo($result -> response[0] -> bdate);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question