Example code

From Shapelink Developer Wiki
Jump to: navigation, search

Php example code

<?php

$params = array(
	'apikey'	=>	'api key',
	'id'		=>	1,
	'type'		=>	'sport',
	'culture'	=>	'en'
);


// Generate signature

$str = '';
	
ksort($params);

foreach ($params as $k=>$v)
	$str .= "$k=$v";

$str .= $secret;

$params['sig'] = md5(strtolower($str));


// Generate params string

$post_params = array();

foreach ($params as $key => $val) 
	$post_params[] = $key.'='.urlencode($val);

$post_string = implode('&', $post_params);


// Contact api

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://api.shapelink.com/diary/getActivities');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

$result = curl_exec($ch);

print_r(json_decode($result));

?>


More information