Translations of this page:
 

This is an old revision of the document!


readAPI()

array readAPI(string API ID, string request, [string API Key])

APIs (standardized interfaces, Application Programming Interface) allow third-party services to be incorporated into the developer's own software or questionnaire. The function readAPI() accesses these services directly within the questionnaire.

  • API ID
    The ID of the service to be used. Currently, SoSci Survey supports the following APIs:
  • request
    the request to the API, coded in GET format
  • API Key
    If the use of the API requires a key to be specifed, this is entered as the third parameter. Normally a key is used to calculate the bill for API services.

The function translates the answer of the API directly in an array, which can be set up relatively easily under PHP. Use the function debug(), in order to display the content of the answer.

Example

// request to Google Maps (search for a street using coordinates)
$v = readAPI('google.maps.v3','latlng=40.714224,-73.961452&sensor=false');
debug($v);
// output of street found
html('<p>Straße: '.$v['results'][0]['address_components'][1]['long_name'].'</p>');
// request to Cloudmade
$v = readAPI('cloudmade.geocoding.v2','around=52.4870,13.4248&distance=closest&object_type=address&return_location=true','API-KEY');
debug($v);
en/create/functions/readapi.1417015471.txt.gz · Last modified: 26.11.2014 16:24 by alexander.ritter
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki