Skip to content

Instantly share code, notes, and snippets.

@lichin-lin
Last active August 4, 2017 10:53
Show Gist options
  • Save lichin-lin/6864769cd1eacdb71d72e05f269a3e52 to your computer and use it in GitHub Desktop.
Save lichin-lin/6864769cd1eacdb71d72e05f269a3e52 to your computer and use it in GitHub Desktop.
fbchat test
import facebook
from fbchat import Client
from fbchat.models import *
from datetime import datetime
server_last_check_time = datetime.now()
client = Client('粉絲帳號', '粉絲密碼..有這東西ㄇXD')
while True:
graph = facebook.GraphAPI(access_token='EAACEdEose0cBAGqKM6rDLTrXipOAd3Kr5ldLGprF2BSCF0Mjp9bWuP0OZBwYrwEaDC1bvPZAeYONpBYdZB04hTy0YRyB9WZAoW356UURclLhS9aVTTqP65oRdOsMhUOqftPKUbCnyZCFNkhyW682ZBaQqwMs6ySYjcHw6tfBy6eYpURVEujGHhDnrAZCuskeLEZD', version='2.9')
post = graph.get_object(id='828387647183801_1513830195306206', fields='comments')
for single in post['comments']['data']:
user_submit_time = datetime.strptime(single['created_time'], '%Y-%m-%dT%H:%M:%S+%f')
if user_submit_time > server_last_check_time:
send_message = '你剛剛是不是打: ' + single['message'] + '對吧?'
target_user = single['from']['id']
client.sendMessage(send_message, thread_id=target_user, thread_type=ThreadType.USER)
print('Start Fetch...Time: ', datetime.now())
server_last_check_time = datetime.now()
sleep(60)
### shut down the script
client.logout()
# print(single['message'], ', ', single['from']['id'], ', ', single['created_time'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment