我正在尝试对Tinder API进行身份验证。可以在变量初始化下方的链接中找到运行此 API 的 Facebook 凭据。
运行下面的代码片段时出现以下错误:
Traceback (most recent call last):
File "C:/Users/tinder.py", line 19, in <module>
tinder_auth_token = req.json()['token']
KeyError: 'token'
我的代码:
import requests
import json
#follow facebook credentials can be found at the following links.
fb_auth_token = get_fb_access_token(email, password)
#https://elfsight.com/blog/2017/10/how-to-get-facebook-access-token/
fb_user_id = get_fb_id(fb_auth_token)
#'https://graph.facebook.com/me?access_token='
def get_auth_token(fb_auth_token, fb_user_id):
headers = {
'app_version': '6.9.4',
'platform': 'ios',
"content-type": "application/json",
"User-agent": "Tinder/7.5.3 (iPhone; iOS 10.3.2; Scale/2.00)",
"Accept": "application/json"
}
if "error" in fb_auth_token:
return {"error": "could not retrieve fb_auth_token"}
if "error" in fb_user_id:
return {"error": "could not retrieve fb_user_id"}
url = 'https://api.gotinder.com/auth'
req = requests.post(url,
headers=headers,
data={'facebook_token': fb_auth_token, 'facebook_id': fb_user_id}
)
try:
tinder_auth_token = req.json()['token']
print(tinder_auth_token)
headers.update({"X-Auth-Token": tinder_auth_token})
url = 'https://api.gotinder.com/user/reset'
r = requests.post(url, headers=headers)
r.json()
print("Success")
except requests.exceptions.ConnectionError as e:
r = "No response"
print(r)