我正在尝试访问 Immoscout24.de API。我是 python 初学者 - 感谢您的支持和耐心。我的(远)目标是将房地产对象放入数据库并比较报价。
从 API 文档中,我了解到 2-legged oauth 足以满足我的目的(https://api.immobilienscout24.de/api-docs/authentication/introduction/)。此外,由于不涉及令牌(https://api.immobilienscout24.de/api-docs/authentication/two-legged/),这似乎是更容易的开始。
这是我尝试过的:
import requests
from requests_oauthlib import OAuth1Session
from requests_oauthlib import OAuth1
CONSUMER_KEY = <key>
CONSUMER_SECRET = <secret>
RESOURCE_URL = "https://rest.immobilienscout24.de/restapi/api/search/v1.0/search/region?realestatetype=houseBuy&geocodes=1276003001046."
oauth = OAuth1Session(
CONSUMER_KEY,
client_secret=CONSUMER_SECRET,
realm=RESOURCE_URL
)
headeroauth = OAuth1(
CONSUMER_KEY,
client_secret=CONSUMER_SECRET
)
r = requests.get(RESOURCE_URL, auth=headeroauth) # results in error 412
[also tried:]
r = oauth.get(RESOURCE_URL) # results in error 400
print(r)
谢谢你的帮助。