Help, displays an empty window when executing the request

<?php $url = "http://vk.com"; $request_params = array( 'url' => $url, 'v' => '5.63' ); $get_params = http_build_query($request_params); $result = json_decode(file_get_contents('https://api.vk.com/method/utils.getShortLink?'. $get_params)); echo($result -> response[0] -> short_url); ?> 
  • one
    so, where did you get that you are right here for a 10,000% answer with data in which there is a short_url , and not an error message? - Alexey Shimansky

1 answer 1

As already noted, utils.getShortLink actually returns error No. 15 (access error), because this method must be called with the access key , passing it in the access_token parameter.

If your application is working on behalf of any VC user, I think it would be advisable to use the already received token. If you want to shorten the link without being tied to the current user, pass the service access key, which can be found in the application settings.


And yes, because only one response is returned, remove the indexer from the response field. There is no array.

  • <?php $access_token = 'token'; $url = 'https://vk.coms' $request_params = array( 'user_id' => $access_token, 'url' => $url, 'v' => '5.63' ); $get_params = http_build_query($request_params); $result = json_decode(file_get_contents('https://api.vk.com/method/utils.getShortLink?'. $get_params)); echo($result -> response -> short_url); ?> <?php $access_token = 'token'; $url = 'https://vk.coms' $request_params = array( 'user_id' => $access_token, 'url' => $url, 'v' => '5.63' ); $get_params = http_build_query($request_params); $result = json_decode(file_get_contents('https://api.vk.com/method/utils.getShortLink?'. $get_params)); echo($result -> response -> short_url); ?> Error 500 - Perumn
  • @Perumn is not 'user_id' => $access_token, and 'access_token' => $access_token, ......... I hope you understand the difference? ...... errors are all painted in response ........ why don't you sometimes look at them? - Alexey Shimansky
  • @ Alexey Shimansky oh, my joint. How to view errors? - Perumn
  • @Perumn var_dump or print_r ....... you print out $result->response and see what exactly is coming to you - Alexey Shimansky