-
Notifications
You must be signed in to change notification settings - Fork 0
/
tinder_api.py
390 lines (320 loc) · 12 KB
/
tinder_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# coding=utf-8
import json
import config
import requests
import fb_auth_token
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",
# "X-Auth-Token": tinder_token
}
def get_tinder_token(fb_username, fb_password):
fb_access_token = fb_auth_token.get_access_token(fb_username, fb_password)
if fb_access_token is None:
return False, -1
url = config.host + "/v2/auth/login/facebook"
payload = {"token": fb_access_token}
resp = requests.post(url, headers=headers, json=payload).json()
if resp["meta"]["status"] != 200:
return False, resp["meta"]["status"]
token = resp["data"]["api_token"]
headers.update({"X-Auth-Token": token})
return True, 0
def get_auth_token(fb_auth_token, fb_user_id):
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 = config.host + '/auth'
req = requests.post(url,
headers=headers,
data=json.dumps(
{'facebook_token': fb_auth_token, 'facebook_id': fb_user_id})
)
try:
tinder_auth_token = req.json()["token"]
headers.update({"X-Auth-Token": tinder_auth_token})
print("You have been successfully authorized!")
return tinder_auth_token
except Exception as e:
print("error")
print(e)
return {"error": "Something went wrong. Sorry, but we could not authorize you."}
def authverif():
res = get_auth_token(config.fb_access_token, config.fb_user_id)
if "error" in res:
return False
return True
def get_recommendations():
'''
Returns a list of users that you can swipe on
'''
try:
r = requests.get('https://api.gotinder.com/user/recs', headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong with getting recomendations:", e)
def get_updates(last_activity_date=""):
'''
Returns all updates since the given activity date.
The last activity date is defaulted at the beginning of time.
Format for last_activity_date: "2017-07-09T10:28:13.392Z"
'''
try:
url = config.host + '/updates'
r = requests.post(url,
headers=headers,
data=json.dumps({"last_activity_date": last_activity_date}))
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong with getting updates:", e)
def get_self():
'''
Returns your own profile data
'''
try:
url = config.host + '/profile'
r = requests.get(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not get your data:", e)
def change_preferences(**kwargs):
'''
ex: change_preferences(age_filter_min=30, gender=0)
kwargs: a dictionary - whose keys become separate keyword arguments and the values become values of these arguments
age_filter_min: 18..46
age_filter_max: 22..55
age_filter_min <= age_filter_max - 4
gender: 0 == seeking males, 1 == seeking females
distance_filter: 1..100
discoverable: true | false
{"photo_optimizer_enabled":false}
'''
try:
url = config.host + '/profile'
r = requests.post(url, headers=headers, data=json.dumps(kwargs))
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not change your preferences:", e)
def get_meta():
'''
Returns meta data on yourself. Including the following keys:
['globals', 'client_resources', 'versions', 'purchases',
'status', 'groups', 'products', 'rating', 'tutorials',
'travel', 'notifications', 'user']
'''
try:
url = config.host + '/meta'
r = requests.get(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not get your metadata:", e)
def get_meta_v2():
'''
Returns meta data on yourself from V2 API. Including the following keys:
['account', 'client_resources', 'plus_screen', 'boost',
'fast_match', 'top_picks', 'paywall', 'merchandising', 'places',
'typing_indicator', 'profile', 'recs']
'''
try:
url = config.host + '/v2/meta'
r = requests.get(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not get your metadata:", e)
def update_location(lat, lon):
'''
Updates your location to the given float inputs
Note: Requires a passport / Tinder Plus
'''
try:
url = config.host + '/passport/user/travel'
r = requests.post(url, headers=headers, data=json.dumps({"lat": lat, "lon": lon}))
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not update your location:", e)
def reset_real_location():
try:
url = config.host + '/passport/user/reset'
r = requests.post(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not update your location:", e)
def get_recs_v2():
'''
This works more consistently then the normal get_recommendations becuase it seeems to check new location
'''
try:
url = config.host + '/v2/recs/core?locale=en-US'
r = requests.get(url, headers=headers)
return r.json()
except Exception as e:
print('excepted')
def set_webprofileusername(username):
'''
Sets the username for the webprofile: https://www.gotinder.com/@YOURUSERNAME
'''
try:
url = config.host + '/profile/username'
r = requests.put(url, headers=headers,
data=json.dumps({"username": username}))
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not set webprofile username:", e)
def reset_webprofileusername(username):
'''
Resets the username for the webprofile
'''
try:
url = config.host + '/profile/username'
r = requests.delete(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not delete webprofile username:", e)
def get_person(id):
'''
Gets a user's profile via their id
'''
try:
url = config.host + '/user/%s' % id
r = requests.get(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not get that person:", e)
def send_msg(match_id, msg):
try:
url = config.host + '/user/matches/%s' % match_id
r = requests.post(url, headers=headers,
data=json.dumps({"message": msg}))
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not send your message:", e)
def unmatch(match_id):
try:
url = config.host + '/user/matches/%s' % match_id
r = requests.delete(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not unmatch person:", e)
def superlike(person_id):
try:
url = config.host + '/like/%s/super' % person_id
r = requests.post(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not superlike:", e)
def like(person_id):
try:
url = config.host + '/like/%s' % person_id
r = requests.get(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not like:", e)
def dislike(person_id):
try:
url = config.host + '/pass/%s' % person_id
r = requests.get(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not dislike:", e)
def report(person_id, cause, explanation=''):
'''
There are three options for cause:
0 : Other and requires an explanation
1 : Feels like spam and no explanation
4 : Inappropriate Photos and no explanation
'''
try:
url = config.host + '/report/%s' % person_id
r = requests.post(url, headers=headers, data={
"cause": cause, "text": explanation})
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not report:", e)
def match_info(match_id):
try:
url = config.host + '/matches/%s' % match_id
r = requests.get(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not get your match info:", e)
def all_matches():
try:
url = config.host + '/v2/matches'
r = requests.get(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not get your match info:", e)
def fast_match_info():
try:
url = config.host + '/v2/fast-match/preview'
r = requests.get(url, headers=headers)
count = r.headers['fast-match-count']
# image is in the response but its in hex..
return count
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not get your fast-match count:", e)
def trending_gifs(limit=3):
try:
url = config.host + '/giphy/trending?limit=%s' % limit
r = requests.get(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not get the trending gifs:", e)
def gif_query(query, limit=3):
try:
url = config.host + '/giphy/search?limit=%s&query=%s' % (limit, query)
r = requests.get(url, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not get your gifs:", e)
##################
def set_location(lat, lon):
try:
url = config.host + '/v2/meta'
payload = {
"lat": float(lat),
"lon": float(lon),
"force_fetch_resources": True
}
r = requests.post(url, json=payload, headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong: ", e)
def get_LQ_rec():
urls = []
ids = []
names = []
recs = get_recommendations()
am = len(recs["results"])
for number in range(am):
id = recs["results"][number]["_id"]
name = recs["results"][number]["name"]
ids.append(id)
names.append(name)
lq_url = recs["results"][number]["photos"][0]["processedFiles"][2]["url"]
urls.append(lq_url)
return list(zip(ids, urls, names))
def get_teasers():
try:
url = config.host + '/v2/fast-match/teasers'
params = {
"locale": "nl"
}
r = requests.get(url, headers=headers, params=params)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not get your fast-match count:", e)
def get_teaser():
try:
url = config.host + '/v2/fast-match/teaser'
params = {
"locale": "nl"
}
r = requests.get(url, headers=headers, params=params)
return r.json()
except requests.exceptions.RequestException as e:
print("Something went wrong. Could not get your fast-match count:", e)