此Tinder API调用返回500错误

2024-05-29 07:48:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试验证到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)

Tags: httpscomtokenauthidjsonurlget

热门问题