0

I am working on selecting json data from yandex maps api. When I call a URL from browser, it's giving me true response. But it's not giving me same response when I called this request in php. Giving 403 unauthorized error.

Here is the URL and you can see true response: https://api-maps.yandex.ru/services/route/2.0/?lang=en_US&token=611617dfbcd24e24fa911f47508ee55a&rll=28.890645900000003%2C41.020271699999995~29.011496%2C41.069194&rtm=atm&sco=latlong&search_type=geo

Here is my PHP code:

$mapUrl = "https://api-maps.yandex.ru/services/route/2.0/?lang=en_US&token=611617dfbcd24e24fa911f47508ee55a&rll=".$basLongitude."%2C".$basLatitude."~".$varLatitude."%2C".$varLongitude."&rtm=atm&sco=latlong&search_type=geo";
$json = file_get_contents($mapUrl);
print_r($json); 

Here is the response:

{
status: "error",
message: "unauthorized",
code: 403
}

Why it's giving diffrent response? Thanks a lot :)

tucecang
  • 1
  • 1
  • 5
  • 1
    Welcome to SO. Most of the time it is better to go and readup on the API that you use, and how to implement that. An unauthorized error basically give you the answer already. Go dig into the documentation – Jaques Oct 06 '15 at 11:34
  • Hello @Jaques thaks for your answer. But this request is working on browser. If you click url, you will see response is not giving any error. – tucecang Oct 06 '15 at 11:41

1 Answers1

1

You can't use this service directly, it violates ToS.

Kirill Dmitrenko
  • 3,474
  • 23
  • 31