class FacebookMessager:

    client = False

    def __init__(self):
        print "App init"
        self.auth()
        self.sendMessage()

    def auth(self):
        # check if next accout ! exists
        # and set cursor to the start of array
        if conf['currentUser'] >= len(users):
            conf['currentUser'] = 0

        user = users[conf['currentUser']]

        # make auth
        print "log in as %s \n" % user['name']
        self.client = Facebook(user['login'], user['password'])
        time.sleep( 5 )
        self.client.ping()

    def sendMessage(self):

        # switch between accounts
        if conf['sended'] % 5 == 0 :
            time.sleep(120)
            conf['currentUser'] = conf['currentUser'] + 1
            self.auth()

        # send mesage
        recipient = collection.find_one({"sended": {"$exists": False} })
        print "send %s" % recipient['user_id']
        send = self.client.send_person( recipient['user_id'], messages['joinGroup'])
        print send

        # update changes
        collection.update_one(
            {"user_id": recipient['user_id']},
            {"$set": { "sended": 1 } }
        )

        # save logs
        conf['sended'] = conf['sended'] + 1
        with open('conf.json', 'w') as outfile:
            json.dump(conf, outfile)

        time.sleep( 50 )
        self.sendMessage()
    def auth(self):
        # check if next accout ! exists
        # and set cursor to the start of array
        if conf['currentUser'] >= len(users):
            conf['currentUser'] = 0

        user = users[conf['currentUser']]

        # make auth
        print "log in as %s \n" % user['name']
        self.client = Facebook(user['login'], user['password'])
        time.sleep( 5 )
        self.client.ping()
def get_access_token(username, password):
  f = Facebook(username, password)
  return f.get_access_token()
Exemple #4
0
import re
import json
import logging

import requests
from facebot import Facebook
from facebot.message import send_person

logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.INFO)

USERNAME = ''
PASSWORD = ''
fb = Facebook(USERNAME, PASSWORD)
log.info('login %s', fb.user_id)


def get_sticky():
    '''
    Call pull api to get sticky and pool parameter,
    newer api needs these parameter to work.
    '''
    url = 'https://0-edge-chat.facebook.com/pull?channel=p_{user_id}&partition=-2&clientid=3396bf29&cb=gr6l&idle=0&cap=8&msgs_recv=0&uid={user_id}&viewer_uid={user_id}&state=active&seq=0'

    # call pull api, and set timeout as one minute
    res = fb.session.get(url.format(user_id=fb.user_id), timeout=60)

    # remove for (;;); so we can turn them into dictionaries
    content = json.loads(re.sub('for \(;;\); ', '', res.text))
Exemple #5
0
FACEBOOK_GENIE_USERID = '708914472545164'
FACEBOOK_DTSG = 'AQGpKj4g31Ga:AQGs9zDgoS4V'
FACEBOOK_COOKIES_DICT = {
    'datr': '65mHVEWhckhJYqK1NGmjanO5',
    'sb': '5xQTV2c31vv26X6eX_sIg9F4',
    'c_user': '******',
    'fr': '0xZp3vNI1cSznnQRW.AWVKM40IiC5ZojJrp--TgOupHPY.BXExTn.q8.AAA.0.AWVaGwIP',
    'xs': '109:7gwRepTXYxZhAA:2:1460868327:19808',
    'csm': '2',
    's': 'Aa7Rn-F_IL2jiNqQ.BXExTn',
    'pl': 'n',
    'lu': 'TisfV88GYaSoS2ryiEehnECw'
}

# setup facebook object
facebook_object = Facebook(FACEBOOK_USERID, FACEBOOK_DTSG)

# add in cookies we need
for k in FACEBOOK_COOKIES_DICT:
    facebook_object.add_session_cookie(k, FACEBOOK_COOKIES_DICT[k], domain='.facebook.com')

# constantly check for new messages/convos
while True:

    # get all the conversations for the genie page
    convos = facebook_object.get_all_conversations(FACEBOOK_GENIE_USERID)

    # loop through each conversation and get the messages for it
    for convo in convos:
        conversation_id = convo["thread_fbid"]
        # print 'Pulling messages for conversation: [%s]' % conversation_id
Exemple #6
0
FACEBOOK_GENIE_USERID = '708914472545164'
FACEBOOK_DTSG = 'AQGpKj4g31Ga:AQGs9zDgoS4V'
FACEBOOK_COOKIES_DICT = {
    'datr': '65mHVEWhckhJYqK1NGmjanO5',
    'sb': '5xQTV2c31vv26X6eX_sIg9F4',
    'c_user': '******',
    'fr': '0xZp3vNI1cSznnQRW.AWVKM40IiC5ZojJrp--TgOupHPY.BXExTn.q8.AAA.0.AWVaGwIP',
    'xs': '109:7gwRepTXYxZhAA:2:1460868327:19808',
    'csm': '2',
    's': 'Aa7Rn-F_IL2jiNqQ.BXExTn',
    'pl': 'n',
    'lu': 'TisfV88GYaSoS2ryiEehnECw'
}

# setup facebook object
facebook_object = Facebook(FACEBOOK_USERID, FACEBOOK_DTSG)

# add in cookies we need
for k in FACEBOOK_COOKIES_DICT:
    facebook_object.add_session_cookie(k, FACEBOOK_COOKIES_DICT[k], domain='.facebook.com')

# constantly check for new messages/convos
while True:

    # get all the conversations for the genie page
    convos = facebook_object.get_all_conversations(FACEBOOK_GENIE_USERID)

    # loop through each conversation and get the messages for it
    for convo in convos:
        conversation_id = convo["thread_fbid"]
        # print 'Pulling messages for conversation: [%s]' % conversation_id