Diese Website existiert nur weil wir Werbung mit AdSense ausliefern.
Bitte den AdBlocker daher auf dieser Website ausschalten! Danke.

API Calls per Script in GAPP

Globalcaching Application (GAPP). Ein Programm für Geocache-Verwaltung unter Windows.

Moderator: SKAMS

Antworten
Benutzeravatar
sally04
Geocacher
Beiträge: 95
Registriert: Sa 5. Apr 2008, 17:41
Wohnort: 45711 Datteln
Kontaktdaten:

API Calls per Script in GAPP

Beitrag von sally04 » So 20. Jul 2014, 11:47

Hallo,
besteht die Möglichkeit ein Script zu schreiben mit dem man einzelne Logs zu Caches abfragen kann?

Mir schwebt etwas in der Art "$api.GetGCLogbyID($token,$ID)"

Und die ID wäre z.B. für dieses Log http://coord.info/GLEFMYBB 414873850

Geht das?

Werbung:
Benutzeravatar
globalcaching.eu
Geocacher
Beiträge: 157
Registriert: Mo 4. Apr 2011, 19:34
Wohnort: Niederlande
Kontaktdaten:

Re: API Calls per Script in GAPP

Beitrag von globalcaching.eu » Mo 21. Jul 2014, 14:20

Quick answer is: Yes
In GAPP you have access to everything, all data and Live API stuff.
At this moment I cannot create a script, because I am at work.

- Robert

Benutzeravatar
sally04
Geocacher
Beiträge: 95
Registriert: Sa 5. Apr 2008, 17:41
Wohnort: 45711 Datteln
Kontaktdaten:

Re: API Calls per Script in GAPP

Beitrag von sally04 » Mi 23. Jul 2014, 18:41

Das was ich vor habe funktioniert scheinbar nicht. Ich habe nur die Methoden GetGeocacheLogsByCacheCode bzw. GetUsersGeocacheLogs gefunden. Die Auswahl des Logs anhand der LogID wird von der API scheibar nicht unterstützt.

Eventuell könnte man GetUsersGeocacheLogs mit einem passenden Request dazubringen mir die speziellen Logs zu liefern.

Ich forsche mal weiter.......

Benutzeravatar
globalcaching.eu
Geocacher
Beiträge: 157
Registriert: Mo 4. Apr 2011, 19:34
Wohnort: Niederlande
Kontaktdaten:

Re: API Calls per Script in GAPP

Beitrag von globalcaching.eu » Mi 23. Jul 2014, 20:09

Ah, I see. I didn't check if the Live API has such a method. I just assumed it did, looking at your request.

GetGeocacheLogsByCacheCode is probably not an option since it is very limited regarding number of calls per hour (or day even).

GetUsersGeocacheLogs is an option. I use it sometimes and getting logs of a user is rather easy and most importantly not limited as GetGeocacheLogsByCacheCode.
But right now, you can only filter on log type and between dates. If you know the date and user name, this might be the way to go.

Benutzeravatar
sally04
Geocacher
Beiträge: 95
Registriert: Sa 5. Apr 2008, 17:41
Wohnort: 45711 Datteln
Kontaktdaten:

Re: API Calls per Script in GAPP

Beitrag von sally04 » Mi 23. Jul 2014, 22:24

Funktioniert.

Dieser "Quick and Dirty"-Code listet 10 meiner Logs (außer der Fundlogs) Über die API

Code: Alles auswählen

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GlobalcachingApplication.Framework.Interfaces;
using GlobalcachingApplication.Utils;
using GlobalcachingApplication.Utils.BasePlugin;

class Script
{
    public static bool Run(Plugin plugin, ICore core)
    { 
        var logs = new List<GlobalcachingApplication.Utils.API.LiveV6.GeocacheLog>();

        using (var api = new GlobalcachingApplication.Utils.API.GeocachingLiveV6(core))
        {
            
                var req = new GlobalcachingApplication.Utils.API.LiveV6.GetUsersGeocacheLogsRequest();
				var i=0;
                req.AccessToken = api.Token;
                req.Username = "sally04";
                req.ExcludeArchived = true;
                req.MaxPerPage = 10;
                req.StartIndex = 0;
				// All Logs but no "Found It"
                req.LogTypes = (from a in core.LogTypes where a.ID>2 select (long)a.ID).ToArray();
                var resp = api.Client.GetUsersGeocacheLogs(req);
				
                while (resp.Status.StatusCode == 0)
                {
					for(i=0; i< resp.Logs.Count() ; i=i+1) {
						System.Windows.Forms.MessageBox.Show(resp.Logs[i].CacheCode+" "+resp.Logs[i].LogText);
					}
					logs.AddRange(resp.Logs);
                    if (resp.Logs.Count() >= req.MaxPerPage)
					{
                        req.StartIndex = logs.Count;
                        resp = api.Client.GetUsersGeocacheLogs(req);
                    }
                    else
                    {
                        break;
                    }
                }
            
        }
		System.Windows.Forms.MessageBox.Show("Loop Fertig");
        return true;
    }
}

Benutzeravatar
globalcaching.eu
Geocacher
Beiträge: 157
Registriert: Mo 4. Apr 2011, 19:34
Wohnort: Niederlande
Kontaktdaten:

Re: API Calls per Script in GAPP

Beitrag von globalcaching.eu » Do 24. Jul 2014, 07:22

Great!

However, some remarks;
I don't think you get only the last 10. If so it is by change.
You get maximum 10 logs and if you get 10 you get the next 10.
Besides, you have to be carefull here. You have req.ExcludeArchived = true;
Lets say your last note is archived. You would expect you get 10 logs excluding your last note. But Groundspeak returns 9 logs (breaking your loop).
I don't know if Groundspeak has changed this awkward behaviour (because you wouldn't expect this). If not, you have to continue getting logs while you get no result anymore.


But I am glad you get this working. I hope that with the source code of GAPP you get enough examples to create scripts.
Note that if you have created a script which you might think is usefull for more people, you can send it to me and I will either make it available through the package manager or I will add it to GAPP functionality (plugin)

- Robert

Antworten