API
i2h.de bietet eine einfache REST-API an, um die Funktionalitäten in eigene Webseiten, Anwendungen oder Plugins zu integrieren.
API-Url
http://api.i2h.de/v1/
API-Parameter
| Parameter |
mögl. Werte |
Default |
Pflichtfeld |
Beschreibung |
| method |
shrink, unshrink, stats |
shrink |
NEIN |
Methode die ausgeführt werden soll. |
| url |
gültige Url |
|
JA |
Bel. URL, die URL-encoded sein muss. |
| format |
text, xml, json, bb-code, html |
text |
NEIN |
Ausgabeformat |
| callback |
Funktion |
|
NEIN |
Javascript Funktion die mit dem Ergebnis als Parameter aufgerufen wird. Nur bei Format = json mögl. |
| appid |
bel. String |
|
NEIN |
Frei wählbare Application ID für Statistikzwecke. Z.B. "iphoneapp" oder "myprog". Die appid muss URL-encoded sein. |
Beispielaufrufe:
-
Aufruf
http://api.i2h.de/v1/?url=http://www.golem.de
Antwort
http://i2h.de/3
-
Aufruf
http://api.i2h.de/v1/?format=xml&url=http://www.golem.de
Antwort
<?xml version='1.0' standalone='yes' ><i2h><links><link><![CDATA[http://i2h.de/3]]></link></links></i2h>
-
Aufruf
http://api.i2h.de/v1/?format=json&url=http://www.golem.de
Antwort
{'links':['http://i2h.de/3']}
- http://api.i2h.de/v1/?url=http://www.golem.de&appid=jupptools
- http://api.i2h.de/v1/?method=shrink&url=http://www.golem.de
- http://api.i2h.de/v1/?method=shrink&url=http://www.golem.de&format=xml
- http://api.i2h.de/v1/?method=stats&url=http://i2h.de/77
- http://api.i2h.de/v1/?method=stats&url=http://i2h.de/77&format=json
Beispielcodes:
PHP: URL shrinken:
<?php
$long_url = 'http://php.net/manual/de/function.trim.php';
$short_url = file_get_contents('http://api.i2h.de/v1/?appid=apiexample&method=shrink&url='. urlencode($long_url));
echo $short_url;
?>
PHP: URL unshrinken:
<?php
$short_url = 'http://i2h.de/m09';
$long_url = file_get_contents('http://api.i2h.de/v1/?appid=apiexample&method=unshrink&url='. urlencode($short_url));
echo $long_url;
?>
Javascript: URL shrinken mit callback:
<script type="text/javascript">
function myCallback(result) {
if(!result.error) {
alert(result.links);
}
}
</script>
<script type="text/javascript" src="http://api.i2h.de/v1/?appid=apiexample&format=json&callback=myCallback&method=shrink&url=http%3A%2F%2Fphp.net%2Fmanual%2Fde%2Ffunction.trim.php"></script>
Links