get_map not passing the API key (HTTP status was '403 Forbidden')

后端 未结 4 863
别跟我提以往
别跟我提以往 2020-11-28 12:27

I have been facing this issue in the get_map() function (ggmap library) in R.

My code was running without the need to specify an API key

4条回答
  •  误落风尘
    2020-11-28 12:59

    You need to use register_google(key = "...") in every new session of R. Using api_key = inside the get_map() call does not work.


    updated: 2018-12-24 for ggmap 2.7.904 and current Google Cloud API

    Step-by-Step Tutorial

    1. Update to newest version of ggmap

    require(devtools)
    devtools::install_github("dkahle/ggmap", ref = "tidyup")
    

    2. Activate your Google API key for all APIs in the Google Cloud Console

    • Link for more info on how to get an API key

    • Direct Link to Google Cloud Platform Console

    • Direct Link to Google Maps API Pricing Information

    • APIs you need: Maps Static and Geocoding

    • Enable billing in the general settings.

    3. Load ggmap and register key

    library(ggmap)
    register_google(key = "...")     # copied directly from Google Console via 'copy' button
    

    4. Plot default map

    ggmap(get_googlemap())          
    

    5. Plot with location name (Geocoding)

    ggmap(get_map("Hannover, Germany"))
    

    If you get an error here (e.g., Forbidden 403) you most probably have not activated your key for the right APIs. Tutorial to troubleshoot geocoding

    6. Plot with longitude and latitude

    ggmap(get_map(location=c(16.3738,48.2082), zoom=13, scale=2))
    

提交回复
热议问题