GSAK (Geocaching Swiss Army Knife)
Contents - Index

GcApi (function)

GcApi(sMethod,[sPostData],[sCaption]) : string


This function is for advanced users and gives you access to the Groundspeak live api

sMethod - The api method to call (see Groundspeak live api link above).

sPostData - Optional and only required if the method uses post data (enter and empty string, if there is no post data and you also want a caption)

sCaption - Optional - a value here will show in the caption of the api dialog that displays when this function is used.

The return string of this function is the XML data returned by the api call, or the error message if the api call ended in error. To determine if the api call ended in error use the system variable $_GcApiError, this variable should be tested after each api call to see if there was an error or not.

To make the parsing out of the returned XML data easier, the function will also automatically create the table "gcapi", in your current database. This table is basically the same as that generated by the XmlToSqlite command.

For methods that only return a small amount of data it may be easier to just manually parse out the xml from the return value of this function. For methods that return many elements then using Sqlite (use action SqlGet to iterate over the entries) to query the gcapi table is probably the better way to go

The gcapi table is only updated when $_GcApiError = False

For example, to show a list of users that favorited the current cache the macro code would be:

 

$data = gcapi("GetUsersWhoFavoritedCache?CacheCode=" + $d_code)
if $_GcApiError
# Error running api, so show the error message
msgok msg=$data
else
$data = sqlite("sql","select data from GcApi where g_Contains('a:UserName',key)","Headings=Y")
$status = sqltohtml($data,"Users that favorited cache - $d_code","Y")
endif


Api methods that need post data are a little harder to construct. 

However, to give you an idea of how to use post data requests, here is the macro code to get the status of a couple of caches:
 

$data = gcapi("GetGeocacheStatus",$status)
if $_GcApiError
# error running api so show error message
msgok msg=$data
else
# api OK now do what you want with the return data
endif

<Data> Varname=$status
<GetGeocacheStatusRequest xmlns="http://www.geocaching.com/Geocaching.Live/data">
<AccessToken>{ACCESSTOKEN}</AccessToken>
<CacheCodes>
   <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">GCGTQ5</string>
   <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">GCGQCA</string>
</CacheCodes>
</GetGeocacheStatusRequest>
<enddata>


More helpful information on the api can be found in this thread.

Alpha List         Category List
Copyright 2004-2019 CWE Computer Services  
Privacy Policy Contact