Casper Casper - 1 month ago 21
Linux Question

How to download Bing Static Map in Linux

I'm trying to download the static map using Bing Maps API. It works when I load the URL from Chrome, but when I tried to curl to wget from Linux, I got Auth Failed error.

The URL are identical but for some reason Bing is blocking calls from Linux?

Here's the commands I tried:

wget -O map.png http://dev.virtualearth.net/REST/V1/Imagery/Map/Road/...
curl -O map.png http://dev.virtualearth.net/REST/V1/Imagery/Map/Road/...


Error:

Resolving dev.virtualearth.net (dev.virtualearth.net)... 131.253.14.8
Connecting to dev.virtualearth.net (dev.virtualearth.net)|131.253.14.8|:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized

Username/Password Authentication Failed.
--2016-10-24 15:42:30-- http://dev.virtualearth.net/REST/V1/Imagery/Map/Road/.../12?mapSize=340,500
Reusing existing connection to dev.virtualearth.net:80.
HTTP request sent, awaiting response... 401 Unauthorized

Username/Password Authentication Failed.


I'm not sure if it has anything to do with Key Type, I've tried several from Public Website to Dev/Test but still didn't work.

Answer

The url needs to be wrapped (because of & symbol in query string that needs to be escaped) with quotes:

wget 'http://dev.virtualearth.net/REST/V1/Imagery/Map/Road/...'

Examples

Via wget:

wget -O map.jpg 'http://dev.virtualearth.net/REST/V1/Imagery/Map/Road/Bellevue%20Washington?mapLayer=TrafficFlow&key=<key>'

Via curl:

curl -o map.jpg 'http://dev.virtualearth.net/REST/V1/Imagery/Map/Road/Bellevue%20Washington?mapLayer=TrafficFlow&key=<key>'

Have been verified under Ubuntu 16.04

Comments