@@ -771,6 +771,23 @@ class Client(object):
|
|||||||
"unseen_threads": j['payload']['unseen_thread_ids']
|
"unseen_threads": j['payload']['unseen_thread_ids']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def fetchImageUrl(self, image_id):
|
||||||
|
"""Fetches the url to the original image from an image attachment ID
|
||||||
|
|
||||||
|
:param image_id: The image you want to fethc
|
||||||
|
:type image_id: str
|
||||||
|
:return: An url where you can download the original image
|
||||||
|
:rtype: str
|
||||||
|
:raises: Exception if request failed
|
||||||
|
"""
|
||||||
|
image_id = str(image_id)
|
||||||
|
j = checkRequest(self._get(ReqUrl.ATTACHMENT_PHOTO, query={'photo_id': str(image_id)}))
|
||||||
|
|
||||||
|
url = get_jsmods_require(j, 3)
|
||||||
|
if url is None:
|
||||||
|
raise Exception('Could not fetch image url from: {}'.format(j))
|
||||||
|
return url
|
||||||
|
|
||||||
"""
|
"""
|
||||||
END FETCH METHODS
|
END FETCH METHODS
|
||||||
"""
|
"""
|
||||||
@@ -833,12 +850,10 @@ class Client(object):
|
|||||||
except (KeyError, IndexError) as e:
|
except (KeyError, IndexError) as e:
|
||||||
raise Exception('Error when sending message: No message IDs could be found: {}'.format(j))
|
raise Exception('Error when sending message: No message IDs could be found: {}'.format(j))
|
||||||
|
|
||||||
# update JS token if receive from response
|
# update JS token if received in response
|
||||||
if ('jsmods' in j) and ('require' in j['jsmods']):
|
fb_dtsg = get_jsmods_require(j, 2)
|
||||||
try:
|
if fb_dtsg is not None:
|
||||||
self.payloadDefault['fb_dtsg'] = j['jsmods']['require'][0][3][0]
|
self.payloadDefault['fb_dtsg'] = fb_dtsg
|
||||||
except (KeyError, IndexError) as e:
|
|
||||||
log.warning("Error when update fb_dtsg. Facebook might have changed protocol.")
|
|
||||||
|
|
||||||
return message_id
|
return message_id
|
||||||
|
|
||||||
|
@@ -220,7 +220,11 @@ class ImageAttachment(Attachment):
|
|||||||
animated_preview_height = int
|
animated_preview_height = int
|
||||||
|
|
||||||
def __init__(self, original_extension=None, width=None, height=None, is_animated=None, thumbnail_url=None, preview=None, large_preview=None, animated_preview=None, **kwargs):
|
def __init__(self, original_extension=None, width=None, height=None, is_animated=None, thumbnail_url=None, preview=None, large_preview=None, animated_preview=None, **kwargs):
|
||||||
"""Represents an image that has been sent as a Facebook attachment"""
|
"""
|
||||||
|
Represents an image that has been sent as a Facebook attachment
|
||||||
|
To retrieve the full image url, use: :func:`fbchat.Client.fetchImageUrl`,
|
||||||
|
and pass it the uid of the image attachment
|
||||||
|
"""
|
||||||
super(ImageAttachment, self).__init__(**kwargs)
|
super(ImageAttachment, self).__init__(**kwargs)
|
||||||
self.original_extension = original_extension
|
self.original_extension = original_extension
|
||||||
self.width = width
|
self.width = width
|
||||||
|
@@ -112,6 +112,7 @@ class ReqUrl(object):
|
|||||||
MESSAGE_REACTION = "https://www.facebook.com/webgraphql/mutation"
|
MESSAGE_REACTION = "https://www.facebook.com/webgraphql/mutation"
|
||||||
TYPING = "https://www.facebook.com/ajax/messaging/typ.php"
|
TYPING = "https://www.facebook.com/ajax/messaging/typ.php"
|
||||||
GRAPHQL = "https://www.facebook.com/api/graphqlbatch/"
|
GRAPHQL = "https://www.facebook.com/api/graphqlbatch/"
|
||||||
|
ATTACHMENT_PHOTO = "https://www.facebook.com/mercury/attachments/photo/"
|
||||||
|
|
||||||
|
|
||||||
facebookEncoding = 'UTF-8'
|
facebookEncoding = 'UTF-8'
|
||||||
@@ -191,3 +192,11 @@ def checkRequest(r, do_json_check=True):
|
|||||||
return j
|
return j
|
||||||
else:
|
else:
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
def get_jsmods_require(j, index):
|
||||||
|
if j.get('jsmods') and j['jsmods'].get('require'):
|
||||||
|
try:
|
||||||
|
return j['jsmods']['require'][0][index][0]
|
||||||
|
except (KeyError, IndexError) as e:
|
||||||
|
log.warning('Error when getting jsmods_require: {}. Facebook might have changed protocol'.format(j))
|
||||||
|
return None
|
||||||
|
Reference in New Issue
Block a user