def new_picture(self, fb_user, fields):
if 'message' not in fields:
fields['message'] = ''
image_file = fields['image']
image_file.seek(0)
mime_type = magic.from_buffer(image_file.read(), mime=True)
image_file.seek(0)
post_data = [('access_token', (None, fb_user.access_token)),
('source', (str(uuid4()) + '.' + mime_type.split('/')[1], image_file)),
('caption', (None, fields['message'])),
('message', (None, fields['message']))]
try:
fb_request_url = Config.get("API_BASE_URI") + "/{}/photos".format(fb_user.username)
resp = requests.post(fb_request_url, files=post_data)
if resp.ok and "post_id" in resp.json():
log.info(_("A new Post with ID {} published!".format(resp.json()['post_id'])))
else:
raise Exception
except Exception:
pass
log.error(_("A failure occurred while posting on Facebook : "
"called with data: {}\n response: {}".format(post_data,
resp.json()
)
)
)
image_file.close()
webhook_data = {
"time": 0,
"id": "101915710270588",
"changed_fields": ["statuses"],
"uid": fb_user.username
}
self.fire_trigger(webhook_data)
评论列表
文章目录