【问题标题】:oauth 401 unauthorized error for heroku app fitbitheroku 应用程序 fitbit 的 oauth 401 未经授权的错误
【发布时间】:2014-03-24 10:37:57
【问题描述】:

我有一个 heroku 应用程序,我正在使用 Auth0 作为通过 oauth 登录的方式运行...我有一些代码或多或少与 fitbit api php 教程 - “completeAuthorization.php”中的代码相同。有点像:

$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());

我从 index.php 页面的 Auth0 响应中获取用户 ID、会话密码和令牌等,但我将它们保存在会话中以将它们保留在我的获取活动页面上。

但是当我在使用 Auth0 登录后转到执行此操作的页面时,我收到此错误: http://api.fitbit.com/1/user/28C9GG/activities/date/2014-02-25.xml 致命错误:未捕获的异常 'OAuthException' 带有消息“无效的身份验证/错误请求(收到 401,预期 HTTP/1.1 20X 或重定向)”

我也只能在安装了 pecl oauth 扩展的网络服务器上做到这一点,但 heroku 没有,我不知道如何在 Heroku 上获得它,对此有任何想法或为什么我得到上述错误?

【问题讨论】:

    标签: php heroku oauth-2.0


    【解决方案1】:

    这是一个可能有用的例子:

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

    特别是查看callback.php,其中调用了 fitbit API

    马蒂亚斯

    【讨论】:

    • 我正要发布这个作为解决方案.. 但看起来你已经找到了。它直到昨天才存在! :P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2012-04-08
    • 1970-01-01
    • 2019-02-12
    • 2017-09-27
    • 2012-12-20
    • 2012-01-28
    相关资源
    最近更新 更多