Last active
November 21, 2018 21:06
-
-
Save wrygiel/4231824 to your computer and use it in GitHub Desktop.
Finding nearest unfound caches with OKAPI
This file contains 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
<?php | |
/* Enter your OKAPI's URL here. */ | |
$okapi_base_url = "https://opencaching.pl/okapi/"; | |
/* Enter your Consumer Key here. */ | |
$consumer_key = "YOUR_KEY_HERE"; | |
/* Caches found by this user will be EXCLUDED from the result. */ | |
$username = "USERNAME_HERE"; | |
/* Your location. */ | |
$lat = 54.3; | |
$lon = 22.3; | |
/* 1. Get the UUID of the user. */ | |
$json = @file_get_contents( | |
$okapi_base_url."services/users/by_username". | |
"?username=".$username. | |
"&fields=uuid". | |
"&consumer_key=".$consumer_key | |
); | |
if (!$json) | |
die("ERROR! Check your consumer_key and/or username!\n"); | |
$user_uuid = json_decode($json)->uuid; | |
print "Your UUID: ".$user_uuid."\n"; | |
/* 2. Search for caches. */ | |
$json = @file_get_contents( | |
$okapi_base_url."services/caches/search/nearest". | |
"?center=".$lat."|".$lon. | |
"¬_found_by=".$user_uuid. | |
"&limit=5". | |
"&consumer_key=".$consumer_key | |
); | |
if (!$json) | |
die("ERROR!"); | |
$cache_codes = json_decode($json)->results; | |
/* Display them. */ | |
print "Five nearest unfound caches: "; | |
print implode(", ", $cache_codes)."\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment