Created
August 30, 2020 00:59
-
-
Save hideack/47d4389fe1ea51474dfda0c2870ce2df to your computer and use it in GitHub Desktop.
ip-api.com を利用した所在地取得
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getRegionName(ip) { | |
| var cache = CacheService.getPublicCache(); | |
| var cacheKey = "api:ip-api.com:" + ip; | |
| var region = cache.get(cacheKey); | |
| if (region == null) { | |
| var geo = UrlFetchApp.fetch("http://ip-api.com/json/" + ip).getContentText(); | |
| region = JSON.parse(geo).regionName; | |
| cache.put(cacheKey, region, 60 * 60 * 8); | |
| } | |
| return region; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment