Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Request Token works in terminal, but doesn't work using CURL+PHP

ANSWERED

Hi!

 

In short:

 

This command works perfectly in terminal:

curl -i -X 'POST' -H 'Authorization: OAuth oauth_version="1.0",oauth_nonce="787c3d7a4e8dd140c8410f73ff9da863",oauth_timestamp="1408118970",oauth_consumer_key="636dxxxxxxxxxxxxxxxxxxx",oauth_signature_method="HMAC-SHA1",oauth_signature="Zy5tqSX32Zv8mQc5gZJXnWsTIoY%3D"' 'https://api.fitbit.com/oauth/request_token'

 

But this PHP code doesn't:

$url = "https://api.fitbit.com/oauth/request_token";
$generatedHeader = 'Authorization: OAuth oauth_version="1.0",oauth_nonce="787c3d7a4e8dd140c8410f73ff9da863",oauth_timestamp="1408118970",oauth_consumer_key="636dxxxxxxxxxxxxxxxxxxx",oauth_signature_method="HMAC-SHA1",oauth_signature="Zy5tqSX32Zv8mQc5gZJXnWsTIoY%3D"';

$options = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => array($generatedHeader),
CURLOPT_HEADER => false,
CURLOPT_VERBOSE => true
);

$curl = curl_init();
curl_setopt_array($curl, $options);
$response = curl_exec($curl);
$info = curl_getinfo($curl);
curl_close($curl);
var_dump($response);

 

This is the response I get from FitBit api server:

{
      "errors":[{
            "errorType":"oauth",
            "fieldName":"oauth_signature",
            "message":"Invalid signature: Zy5tqSX32Zv8mQc5gZJXnWsTIoY="
      }],
      "success":false
}

 

Both Base String and the Signature generated in my code match those ones generated in the FitBit API Debug Tool

 

Since I can get a response using the curl command in terminal, I think it sould be easy to do the same using the curl command inside a PHP environment.

 

Because of internal limitations I can't use the OAuth extension in my application. Do you have any example of how to implement it in PHP, using curl?

 

Kind regards,

 

Paulo Amaral

Best Answer
0 Votes
2 BEST ANSWERS

Accepted Solutions

I doin't  see in your code that you're making a POST request.

Are you sure you're making POST and not GET ?

Ivan Bahdanau
Senior Software Developer at Fitbit

View best answer in original post

Best Answer

ibahdanau, thanks for your reply!

 

You are right, but I tryed that and was not the only issue.

 

Actually, I could put the oauth extension to work in my server, using one of the builds that I found here: http://windows.php.net/downloads/pecl/releases/oauth/ . Now, I am using the FitBitPHP class (https://github.com/heyitspavel/fitbitphp), which works like a charm.

 

Anyway, after posting I noticed that there is a pure php port of the FitBitPHP class, that doesn't need the OAuth extension: https://github.com/TheSavior/fitbitphp .

 

Regards

View best answer in original post

Best Answer
0 Votes
2 REPLIES 2

I doin't  see in your code that you're making a POST request.

Are you sure you're making POST and not GET ?

Ivan Bahdanau
Senior Software Developer at Fitbit
Best Answer

ibahdanau, thanks for your reply!

 

You are right, but I tryed that and was not the only issue.

 

Actually, I could put the oauth extension to work in my server, using one of the builds that I found here: http://windows.php.net/downloads/pecl/releases/oauth/ . Now, I am using the FitBitPHP class (https://github.com/heyitspavel/fitbitphp), which works like a charm.

 

Anyway, after posting I noticed that there is a pure php port of the FitBitPHP class, that doesn't need the OAuth extension: https://github.com/TheSavior/fitbitphp .

 

Regards

Best Answer
0 Votes