how to connect to this api using php?

EOL ForumsAPI newbie questions

how to connect to this api using php?
by eangeles92, Sun Jun 30, 2013 21:43 UTC

how can I connect to this api using php? Thank you!

Profile picture of eangeles92 who took this action.
  • Joined about 1 year ago
  • 2 posts
Re: how to connect to this api using php?
by Yan Wong, Mon Jul 01, 2013 17:34 UTC

how can I connect to this api using php? Thank you!

I use perl, but with PHP you could try something like this, (culled from here). This example uses the url from http://eol.org/api/docs/data_objects. In general, you'll need to construct an appropriate URL of the right form (and you might also want to append your API key, as &key=MYAPIKEY).

<?php

$jsonurl = "http://eol.org/api/data_objects/1.0/24983216.json?cache_ttl=60000";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);

foreach ( $json_output->dataObjects as $objects )
{
    echo "{$objects->title}\n";
}
?>

Profile picture of Yan Wong who took this action.
  • Joined over 1 year ago
  • 92 posts
connect to API with PHP but also via Javascript using JQuery
by newmang, Wed Dec 18, 2013 16:38 UTC
Hi All,

I am new to the EOL API and am trying to access species data.

First, I’ve called the search to get a page ID using the above tips via server side PHP code. I was successul in getting a species EOL Page ID (let's say: 647593 (Acacia abyssinica).

Next, I put this into the following variable in javascript:

var url='http://eol.org/api/pages/1.0/647593.json?images=2&videos=0&sounds=0&maps=0&text=2&iucn=false&subjects=overview&licenses=all&details=true&common_names=true';

I then try two different approaches to get EOL content:

(1)

$.ajax(url);

(2)

var Result=jQuery.parseJSON(jQuery.ajax({url:url,async:false,dataType:'json'}).responseText);

I tried the JQuery AJAX method (first approach above) and when I do so I see a GET in my Firebug debugger that is black and then red in color indicating an error. However, when I retrieve the actual JSON using the 'open in new tab' capability of firebug to see the response from the get, I see valid JSON and I even can copy and paste the returned JSON into a JSON verifier like JSON LINT and I get valid JSON. However, I cannot continue to parse the JSON because of the error being returned.

Any suggestions by you or your IT folks would be great!
Profile picture of newmang who took this action.
  • Joined over 2 years ago
  • 1 post

Make a new post