Instagram, Tagreichweiten und Tags via Json holen und interpretieren.

Möchte man sich die aufwändige Entwicklung eines eigenen Parsers sparen, lässt sich der Export der Daten via API problemlos via JSON realisieren. Hier geht man wiefolgt vor:

[Einbindung der Unit]
uses json;

[Prozedur]
procedure tagdaten_holen;
var lauf: integer;
JSONArray: tJSONArray;
JSONValue: tJSONValue;
JSONPair: TJSONPair;
JSON: TJSONObject;
i: integer;
begin
try
debug.Text:=idhttp1.Get(‚https://api.instagram.com/v1/tags/search?q=’+tagrecherche.text+’&access_token=’+token.text);
JSONValue := TJSONObject.ParseJSONValue(debug.text);
JSON := TJSONObject.ParseJSONValue(debug.Lines.Text) as TJSONObject;
JSONArray := TJSONArray(JSON.Get(‚data‘).JsonValue);
with tagr_roh do
begin
cells[0,0]:=’Nr.‘;
cells[1,0]:=’Tag‘;
cells[2,0]:=’Reichweite‘;
colcount:=3;
rowcount:=1;
end;
for i := 0 to JSONArray.Size – 1 do
begin
with tagr_roh do
begin
cells[0,rowcount]:=inttostr(rowcount);
cells[1,rowcount]:=(TJSONPair(TJSONObject(JSONArray.Get(i)).Get(’name‘)).JsonValue.Value);
cells[2,rowcount]:=(TJSONPair(TJSONObject(JSONArray.Get(i)).Get(‚media_count‘)).JsonValue.Value);
rowcount:=rowcount+1;
end;
end;
except
showmessage(‚Fehler mit der Internetverbindung. Prüfe Diese und den Token!‘);
end;
end;

Schreibe einen Kommentar