rest - FatSecret API - food.get method invalid signature -


hi
new fatsecret platform api , developed php script
access food details using foods.search method
here foods.search method api call example,used curl , works
perfect.

<?php
$consumer_key = "xxxxxxx";
$secret_key = "xxxxxxx";
//signature base string
//<http method>&<request url>&<normalized parameters>
$base = rawurlencode("get")."&";
$base .= "http%3a%2f%2fplatform.fatsecret.com%2frest%2fserver.
api&";

//sort params abc....necessary build correct unique signature
$params = "method=foods.search&";
$params .= "oauth_consumer_key=$consumer_key&"; // ur consumer key
$params .= "oauth_nonce=123&";
$params .= "oauth_signature_method=hmac-sha1&";
$params .= "oauth_timestamp=".time()."&";
$params .= "oauth_version=1.0&";
$params .= "search_expression=".urlencode($_get['pasvar']);
$params2 = rawurlencode($params);
$base .= $params2;

//encrypt it!
$sig= base64_encode(hash_hmac('sha1', $base, "$secret_key&",
true)); // replace xxx consumer secret

//now search results , write them down
$url = "http://platform.fatsecret.com/rest/server.api?".
$params."&oauth_signature=".rawurlencode($sig);

//$food_feed = file_get_contents($url);
list($output,$error,$info) = loadfoods($url);
echo '<pre>';
if($error == 0){
    if($info['http_code'] == '200')
        echo $output;
    else
        die('status info : '.$info['http_code']);

}

else
    die('status error : '.$error);

function loadfoods($url)
{

        // create curl resource
        $ch = curl_init();

        // set url
        curl_setopt($ch, curlopt_url, $url);

        //return transfer string
        curl_setopt($ch, curlopt_returntransfer, 1);

        // $output contains output string
        $output = curl_exec($ch);

        $error = curl_error($ch);

        $info = curl_getinfo($ch);
        // close curl resource free system resources
        curl_close($ch);

        return array($output,$error,$info);

}

?>

the above script working perfect , retrieves food details using
search method.but

when use food.get method retrieve data using food_id says
invalid signature error,here's food.get method api call example,i
have given correct keys , passed food_id parameter.can
me solve issue,i struck on code.it says invalid
signature error.

<?php
$consumer_key = "xxxxxxxxx";
$secret_key = "xxxxxxxxxx";
//signature base string
//<http method>&<request url>&<normalized parameters>
$base = rawurlencode("get")."&";
$base .= "http%3a%2f%2fplatform.fatsecret.com%2frest%2fserver.api&";

//sort params abc....necessary build correct unique signature
$params = "method=food.get&";
$params .= "oauth_consumer_key=$consumer_key&"; // ur consumer key
$params .= "oauth_nonce=".rand()."&";
$params .= "oauth_signature_method=hmac-sha1&";
$params .= "oauth_timestamp=".time()."&";
$params .= "oauth_version=1.0&";
$params .= "food_id=".urlencode($_get['pasvar']);
$params2 = rawurlencode($params);
$base .= $params2;

//encrypt it!
$sig= base64_encode(hash_hmac('sha1', $base, "$secret_key&",
true)); // replace xxx consumer secret

//now search results , write them down
$url = "http://platform.fatsecret.com/rest/server.api?".
$params."&oauth_signature=".rawurlencode($sig);

//$food_feed = file_get_contents($url);
list($output,$error,$info) = loadfoods($url);
echo '<pre>';
if($error == 0){
    if($info['http_code'] == '200')
        echo $output;
    else
        die('status info : '.$info['http_code']);

}

else
    die('status error : '.$error);

function loadfoods($url)
{

        // create curl resource
        $ch = curl_init();

        // set url
        curl_setopt($ch, curlopt_url, $url);

        //return transfer string
        curl_setopt($ch, curlopt_returntransfer, 1);

        // $output contains output string
        $output = curl_exec($ch);

        $error = curl_error($ch);

        $info = curl_getinfo($ch);
        // close curl resource free system resources
        curl_close($ch);

        return array($output,$error,$info);

}

?>

help me what's error in code , me solve issue
have use api in project

thanks waiting replies....

you should order params alpha. should in order:

$params = "food_id=".urlencode($_get['pasvar'])."&";  $params .= "method=food.get&"; $params .= "oauth_consumer_key=$consumer_key&"; // ur consumer key $params .= "oauth_nonce=".rand()."&"; $params .= "oauth_signature_method=hmac-sha1&"; $params .= "oauth_timestamp=".time()."&"; $params .= "oauth_version=1.0"; 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -