[英]How to authenticate Fitbit user with OAuth 2.0?
I am trying to write a web application with Python using the Fitbit API. 我正在尝试使用Fitbit API用Python编写Web应用程序。 I need to authenticate the user with OAuth 2.0 in the browser.
我需要在浏览器中使用OAuth 2.0对用户进行身份验证。 Right now I'm trying to use python-fitbit , though I'm not sure there's a better way to do this.
现在,我正在尝试使用python-fitbit ,尽管我不确定是否有更好的方法可以做到这一点。 Here is my code:
这是我的代码:
import fitbit
client = fitbit.FitbitOauth2Client('client_id', 'client_secret')
res = client.make_request("https://api.fitbit.com/1/user/-/activities.json", None, method='GET')
When I run it, I get ValueError: Missing access token.
当我运行它时,我得到
ValueError: Missing access token.
What am I doing wrong here? 我在这里做错了什么? I feel totally in over my head with this.
我对此深感不安。
Did you notice this known bug in python-fitbit? 您是否注意到python-fitbit中的这个已知错误?
https://github.com/orcasgit/python-fitbit/issues/70 https://github.com/orcasgit/python-fitbit/issues/70
Seems like it might be what you're hitting. 好像是您要击中的东西。 That user described a workaround in using another fitbit python client.
该用户描述了使用另一个fitbit python客户端的解决方法。
Edit: Adding quote from other article for a better answer! 编辑:添加其他文章的报价以获得更好的答案!
As I successfully obtain my token using another Fitbit API client ( https://github.com/magnific0/FitBit.py ), it seems there is a problem with your script "gather_keys_oauth2.py".
当我使用另一个Fitbit API客户端( https://github.com/magnific0/FitBit.py )成功获取令牌时,脚本“ gather_keys_oauth2.py”似乎出现了问题。
I would say that oauthlib call using OAuth2Session should not try to validate the token during the request phase.
我会说使用OAuth2Session的oauthlib调用不应尝试在请求阶段验证令牌。
Looks like the issue was fixed in the code ( gather_keys_oauth2.py ) a week or so ago, but I couldn't find the documentation how to use the fixed code. 看起来该问题已在一周左右的时间内通过代码( collect_keys_oauth2.py )解决,但我找不到如何使用固定代码的文档。
Looking for simple example if possible. 如果可能,寻找简单的例子。
@orcasgit/orcas-developers Please review.
@ orcasgit / orcas-developers请查看。 This should get the OAuth2 authentication working again.
这样可以使OAuth2身份验证再次起作用。 Works in my testing.
在我的测试中有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.