简体   繁体   中英

oauth 401 unauthorized error for heroku app fitbit

I've got a heroku app and I am running with Auth0 as the way of logging in via oauth... I have some code more or less the same as from the fitbit api php tutorial - "completeAuthorization.php". It looks a bit like:

$oauth = new OAuth($conskey, $conssec,        OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->enableDebug();
    }
catch( OAuthException $E ) 
    {
        print_r($E);
    }
echo 'done new oauth';
$oauth->setToken($_SESSION['access_token'], $_SESSION['access_token_secret']);
echo 'done set token';
// Fitbit API call (get activities for specified date)
//http://api.fitbit.com/1/user/28C9GG/activities/date/2013-12-01.xml
$apiCall2 = 'http://api.fitbit.com/1/user/'.$_SESSION['userid'].'/activities/date/2014-02-25.xml';
echo $apiCall2;
    // Performing API call 
    $oauth->fetch($apiCall2);
   //$oauth->fetch($apiCall);
    var_dump($oauth->getLastResponse());

I get the user id, and the session secret and token etc. from the Auth0 response from my index.php page, but I save them in a session to keep them on my get activities page.

But when I go to my page that does this after I log in with Auth0, I get this error: http://api.fitbit.com/1/user/28C9GG/activities/date/2014-02-25.xml Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)'

I am also only able to get this far on my webserver which has a pecl oauth extension installed, but heroku does not and I have no idea how to get it on Heroku, any ideas on this or why I get the above error?

Here is an example that might be useful:

https://github.com/auth0/Auth0-PHP/tree/master/examples/fitbit

In particular look at callback.php where there is a call to fitbit API

Matias

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM