I need help.
no matter what i do i always get an invalid signature for my response.
here is my code:
require_once('lib/config.php');
// Set the search string
${'Search Term'} = 'apple';
// Set the API request Url
${'Request URL'} = '
http://platform.fatsecret.com/rest/server.api';
// Generate the timestamp
${'Time Stamp'} = strtotime(date('m/d/Y h:i:s a', time()));
// Generate the random string for the nonce
${'Random MD5'} = md5(rand(00000000,99999999));
// Build and encode the base string
${'Base String'} = 'POST&'.urlencode(${'Request
URL'}).'&'.urlencode('method=food.search&oauth_consumer_key='.API_KEY.'&oauth_nonce='.
${'Random MD5'}.'&oauth_signature_method=HMAC-SHA1&oauth_timestamp='.$
{'Time Stamp'}.'&oauth_version=1.0&search_expression='.${'Search
Term'});
// Set the key for the sha1
${'Key'} = API_KEY.'&'.API_SECRET;
// Generate the SHA1 for the signature
${'Sha'} = base64_encode(hash_hmac('sha1',${'Base String'},$
{'Key'},true));
// Build the Request with the signature
${'URL'} =
'method=food.search&oauth_consumer_key='.API_KEY.'&oauth_nonce='.$
{'Random MD5'}.'&oauth_signature='.$
{'Sha'}.'&oauth_signature_method=HMAC-SHA1&oauth_timestamp='.${'Time
Stamp'}.'&oauth_version=1.0&search_expression='.${'Search Term'};
// Use cUrl to generate the response
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ${'Request URL'}.'?'.${'URL'});
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
${'Response'} = curl_exec($ch);
curl_close($ch);
echo ${'Response'};