@@ -512,26 +512,28 @@ class Client(object):
|
|||||||
# Strip the start and parse out the returned image_id
|
# Strip the start and parse out the returned image_id
|
||||||
return json.loads(r._content[9:])['payload']['metadata'][0]['image_id']
|
return json.loads(r._content[9:])['payload']['metadata'][0]['image_id']
|
||||||
|
|
||||||
def getThreadInfo(self, userID, start, end=None, thread_type='user'):
|
def getThreadInfo(self, userID, last_n=20, start=None, thread_type='user'):
|
||||||
"""Get the info of one Thread
|
"""Get the info of one Thread
|
||||||
|
|
||||||
:param userID: ID of the user you want the messages from
|
:param userID: ID of the user you want the messages from
|
||||||
:param start: the start index of a thread
|
:param last_n: (optional) number of retrieved messages from start
|
||||||
:param end: (optional) the last index of a thread
|
:param start: (optional) the start index of a thread (Deprecated)
|
||||||
:param thread_type: (optional) change from 'user' for group threads
|
:param thread_type: (optional) change from 'user' for group threads
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not end: end = start + 20
|
assert last_n > 0, 'length must be positive integer, got %d' % last_n
|
||||||
if end <= start: end = start + end
|
assert start is None, '`start` is deprecated, always 0 offset querry is returned'
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
if thread_type == 'user':
|
if thread_type == 'user':
|
||||||
key = 'user_ids'
|
key = 'user_ids'
|
||||||
else:
|
else:
|
||||||
key = 'thread_fbids'
|
key = 'thread_fbids'
|
||||||
|
|
||||||
data['messages[{}][{}][offset]'.format(key, userID)] = start
|
# deprecated
|
||||||
data['messages[{}][{}][limit]'.format(key, userID)] = end
|
# `start` doesn't matter, always returns from the last
|
||||||
|
# data['messages[{}][{}][offset]'.format(key, userID)] = start
|
||||||
|
data['messages[{}][{}][offset]'.format(key, userID)] = 0
|
||||||
|
data['messages[{}][{}][limit]'.format(key, userID)] = last_n
|
||||||
data['messages[{}][{}][timestamp]'.format(key, userID)] = now()
|
data['messages[{}][{}][timestamp]'.format(key, userID)] = now()
|
||||||
|
|
||||||
r = self._post(MessagesURL, query=data)
|
r = self._post(MessagesURL, query=data)
|
||||||
@@ -548,22 +550,21 @@ class Client(object):
|
|||||||
return list(reversed(messages))
|
return list(reversed(messages))
|
||||||
|
|
||||||
|
|
||||||
def getThreadList(self, start, end=None):
|
def getThreadList(self, start, length=20):
|
||||||
"""Get thread list of your facebook account.
|
"""Get thread list of your facebook account.
|
||||||
|
|
||||||
:param start: the start index of a thread
|
:param start: the start index of a thread
|
||||||
:param end: (optional) the last index of a thread
|
:param end: (optional) the last index of a thread
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not end: end = start + 20
|
assert length < 21, '`length` is deprecated, max. last 20 threads are returned'
|
||||||
if end <= start: end = start + end
|
|
||||||
|
|
||||||
timestamp = now()
|
timestamp = now()
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
data = {
|
data = {
|
||||||
'client' : self.client,
|
'client' : self.client,
|
||||||
'inbox[offset]' : start,
|
'inbox[offset]' : start,
|
||||||
'inbox[limit]' : end,
|
'inbox[limit]' : length,
|
||||||
}
|
}
|
||||||
|
|
||||||
r = self._post(ThreadsURL, data)
|
r = self._post(ThreadsURL, data)
|
||||||
@@ -789,13 +790,24 @@ class Client(object):
|
|||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def getUserInfo(self,*user_ids):
|
def getUserInfo(self, *user_ids):
|
||||||
"""Get user info from id. Unordered.
|
"""Get user info from id. Unordered.
|
||||||
|
|
||||||
:param user_ids: one or more user id(s) to query
|
:param user_ids: one or more user id(s) to query
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = {"ids[{}]".format(i):user_id for i,user_id in enumerate(user_ids)}
|
def fbidStrip(_fbid):
|
||||||
|
# Stripping of `fbid:` from author_id
|
||||||
|
if type(_fbid) == int:
|
||||||
|
return _fbid
|
||||||
|
|
||||||
|
if type(_fbid) == str and 'fbid:' in _fbid:
|
||||||
|
return int(_fbid[5:])
|
||||||
|
|
||||||
|
user_ids = [fbidStrip(uid) for uid in user_ids]
|
||||||
|
|
||||||
|
|
||||||
|
data = {"ids[{}]".format(i):uid for i,uid in enumerate(user_ids)}
|
||||||
r = self._post(UserInfoURL, data)
|
r = self._post(UserInfoURL, data)
|
||||||
info = get_json(r.text)
|
info = get_json(r.text)
|
||||||
full_data= [details for profile,details in info['payload']['profiles'].items()]
|
full_data= [details for profile,details in info['payload']['profiles'].items()]
|
||||||
|
Reference in New Issue
Block a user