Invalid signature

83 views
Skip to first unread message

jd vangsness

unread,
May 15, 2012, 9:32:46 PM5/15/12
to FatSecret Platform API
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'};

odie2828

unread,
May 16, 2012, 2:48:03 AM5/16/12
to fatsecret-p...@googlegroups.com
All i am trying to do is search the foods and return the food name and nutritional values.

if there is an easier way then please someone let me know!

John Freeman

unread,
May 16, 2012, 3:23:23 AM5/16/12
to fatsecret-p...@googlegroups.com, odie2828


On Wednesday, May 16, 2012 1:48:03 AM, odie2828 wrote:
> All i am trying to do is search the foods and return the food name and
> nutritional values.

Have you searched the mailing list?

- John

odie2828

unread,
May 16, 2012, 3:24:59 AM5/16/12
to fatsecret-p...@googlegroups.com, odie2828
what do you mean?
Reply all
Reply to author
Forward
0 new messages