Action of Love

A Coalition of LOVE Sharing Acts of Love

This group space is a place where all people can come to share inspirations on Actions of Love.  During these times of Political and Environmental kaos, people who are actively engaged in alternative practices, setting the stepping stones and being the change, can share their visions of hope.  This is a place where people can find inspiration in what others ...learn more

GROUP DETAILS

Created: Feb 03, 2008

Updated: Nov 01, 2009

Membership: Open

Public

 
Created: Oct 29, 2009
Updated: Oct 30, 2009
Viewed: 94 times
Page Status: active
  •  
Not Yet Rated

API Demo Client (PHP)

Edit this Page

Here is some sample code for getting you started using the WiserEarth API. Click here to see a usage example.

 

<?php

 

/*

 * generate the request URL for looking up an entity record

 * @param $entity - (string) singular form of entity name ie. organization, job, event, etc.

 * @param $masterid - (string) the 'masterid' of the object you wish to lookup.

                                 see docs for more info.

 * @param $secret - (string) your WiserEarth API secret

 * @param $key - (string) your WiserEarth API key

 */

function generateLookupUrl($entity, $masterid, $secret, $key)

{

  $sig = generateLookupSig($masterid, $secret);

  $url = 'http://www.wiserearth.org/';

  $url .= $entity . 's';

  $url .= '/' . $masterid . '?sig=' . $sig . '&key=' . $key;


  return $url;

}

 

/*

 * generate the request URL for executing a search.

 * @param $entity - (string) singular form of entity name ie. organization, job, event, etc.

 * @param $params - (array) search parameters. key = parameter, value = value.

 *                            see docs for available search parameters.

 * @param $secret - (string) your WiserEarth API secret

 * @param $key - (string) your WiserEarth API key

 */

function generateSearchUrl($entity, $params, $secret, $key)

{

  $sig = generateSearchSig($params, $secret);

  $url = 'http://www.wiserearth.org/';

  $url .= $entity . 's';

  $url .= '/api_search?' . http_build_query($params) . '&sig=' . $sig . '&key=' . $key;


  return $url;

}

 

function generateLookupSig($masterid, $secret)

{

  $params = array('masterid' => $masterid);

  return generateSig($params, $secret);

}


function generateSearchSig($params, $secret)

{

  return generateSig($params, $secret);

}


function generateSig($params, $secret)

{

  $sig_str = '';

  foreach($params as $key => $value)

  {

    $sig_str .= $key . $value;

  }

  $sig_str .= $secret;

  return md5($sig_str);

}



?>



Usage Example: Search

Save the above code to a file called "api_helper.php". The following example will search for events with the keyword "wiserearth" in Paris, France.

 

<?php
include('api_helper.php');

$key = "429605787e0908d300d6664d3129e90b"; // insert your own API key here
$secret = "1db232f8b3c413ba02fcs585919b3849"; // insert your own API secret here


// setup your search parameters. see API documentation for more search parameters:

//   http://www.wiserearth.org/article/d5f9154fa4cc8681fddb44c40bd8f202

$search_params = array(
  'phrase' => 'wiserearth',
  'anchor_lat' => '48.8566667',
  'anchor_long' => '2.3509871',
  'distance' => '16093.44',
);

echo generateSearchUrl('event',$search_params, $secret, $key) . "\n";

?>

 



Usage Example: Lookup

Save the above code to a file called "api_helper.php". The following example will lookup the WiserTuesdays event in Paris, France.


<?php
include('api_helper.php');

$key = "329605787e0908d300d666483129e90b";
$secret = "edb232f8b3c413ba02fc7585919b3849";
$masterid = "ba40bf8fc222e8203daedc4adb543e86";

echo generateLookupUrl('event',$masterid, $secret, $key) . "\n";

?>


Comments

Login to Post a Comment.


Contributors to this Page