最近,我一直在努力让 OAuth 与 WiThings API 一起工作,使用 Python 3.3。作为参考,这里是 WiThings 的文档:http: //www.withings.com/api
现在......正如我所说,我一直在使用请求库(http://docs.python-requests.org/en/latest/)在 Python 中使用 WiThings API。据说,这已经内置了对 OAuth 1.0 的支持。
使用这个,当我输入我的消费者密钥和消费者秘密,然后执行令牌请求时,我得到这个响应......
b'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>413 Request Entity Too Large</title>\n</head><body>\n<h1>Request Entity Too Large</h1>\nThe requested resource<br />/index.php<br />\ndoes not allow request data with POST requests, or the amount of data provided in\nthe request exceeds the capacity limit.\n<hr>\n<address>Apache Server at oauth.withings.com Port 80</address>\n</body></html>\n'
知道是什么原因造成的吗?我有一种特定于 WiThings 的感觉……但他们的支持很糟糕。
接下来,我做了一些研究,发现了这个:https ://github.com/maximebf/python-withings
虽然文档记录也很差,但我安装了它,并拥有以下代码:
from __future__ import unicode_literals
from urllib.parse import parse_qs
import requests
from requests_oauthlib import OAuth1
import withings
CONSUMER_KEY = "omitted"
CONSUMER_SECRET = "omitted"
auth = WithingsAuth(CONSUMER_KEY, CONSUMER_SECRET)
authorize_url = auth.get_authorize_url()
print("Go to %s allow the app and copy your oauth_verifier" %authorize_url)
oauth_verifier = raw_input('Please enter your oauth_verifier: ')
creds = auth.get_credentials(oauth_verifier)
client = WithingsApi(creds)
measures = client.get_measures(limit=1)
print("Your last measured weight: %skg" % measures[0].weight)
并得到以下错误...
File "withings.py", line 5, in <module>
import withjings
File C:\User_Directory\withings.py", line 11, in <module>
auth = WithingsAuth(CONSUMER_KEY, CONSUMER_SECRET)
NameError: name 'WithingsAuth' is not defined
对这些问题有任何帮助吗?有没有人在 python 中使用 Withings 成功?
谢谢你们的帮助