fbessez / Tinder

Official November 2019 Documentation for Tinder's API (wrapper included)
MIT License
848 stars 197 forks source link

all_matches needs to be updated #111

Open Gabryxx7 opened 4 years ago

Gabryxx7 commented 4 years ago

I noticed that all_matches was not working anymore and afater some investigation it looks like it needs some additional parameters:

def all_matches(count=60, message=0, page_token=None):
    try:
        url = config.host + '/v2/matches?locale=en&count=' + str(count) + '&message=' + str(message) + '&is_tinder_u=false'
        if page_token:
            url = url + '&page_token=' + page_token
        r = requests.get(url, headers=headers)
        json = r.json()
        if 'data' in json.keys() and 'next_page_token' in json['data'].keys():
                next_page_data = all_matches(count, message, json['data']['next_page_token'])
                json['data']['matches'] = json['data']['matches'] + next_page_data['data']['matches']
        return json
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not get your match info:", e)

So now we need to specify count which is usually 60 on the web version. Not sure what message is but if it's set to 1 the response won't contain the next_page_token.

Since the method is called all_matches I added a little recursive loop to add the matches to the json so that the returned json contains all the matches in the data key.

lovetoburnswhen commented 4 years ago

That code isn't valid, were you planning on making a PR?

Gabryxx7 commented 4 years ago

Sorry I couldn't test it at the time, only looked at the Tinder web version. Might as well make a PR :)

Edit: I also re-checked the code above and it should be good now but a PR is definitely better

kmalla123 commented 4 years ago

@Gabryxx7 Your function returns only the latest message sent. Any idea how to extract the whole conversation?

Gabryxx7 commented 4 years ago

Hey, yeah I wrote a method to get all the messages in my own fork: https://github.com/Gabryxx7/AI_Dating/blob/349fda890e5852dd9041e5df74bf22fdef582a21/API/tinder_api_extended.py#L415

Given the match_id you can get messages with this API call: path = '/v2/matches/%s/messages?locale=en&count=%s' % (match_data["_id"], count) This will only return the first count messages, to get the rest you need to pass a page_token which is given in the response of each call.

The method I wrote is recursive and will automatically merge the results, returning a single json object with all the messages

kmalla123 commented 4 years ago

@Gabryxx7 Thanks Gab. I had a quick look at your AI_Dating. Great Content!