GithubHelp home page GithubHelp logo

Client.getAllUsers() about fbchat HOT 5 CLOSED

vincent-lg avatar vincent-lg commented on August 30, 2024 2
Client.getAllUsers()

from fbchat.

Comments (5)

dstelzer avatar dstelzer commented on August 30, 2024

Re feasibility: names and IDs are returned from threadlist_info.php: you can iterate over data['payload']['participants'], which has keys fbid and name, and make a dictionary of them.

Unfortunately, Facebook will only give you the most recent ~80 threads. So this method will only get participants in the most recent 80 conversations.

from fbchat.

Schmavery avatar Schmavery commented on August 30, 2024

What does "all users" even mean? All friends of the bot? All participants of a specific conversation? Like @dstelzer called out, there are some limitations here. Afaik it's pretty hard to have an api call that mimics the behaviour of the sidebar that shows which friends are active without some logic to maintain state clientside.

from fbchat.

vincent-lg avatar vincent-lg commented on August 30, 2024

What I was hoping to do was quite simple, actually: simply get the bot's friends (or part of it, if the complete list isn't possible). @dstelzer, you mentioned a PHP page, but how to interact with it with the bot isn't obvious to me (I'm not very familiar with the API, and I can't find much documentation on the topic). I tried to use the bot.getThreadList() method, or bot.getThreadInfo with a valid Facebook ID, but it doesn't seem I get the information (although I can find most recent messages, the "name" field is always empty). Did I miss something? Or, more accurately, what did I miss?

Thanks!

from fbchat.

vincent-lg avatar vincent-lg commented on August 30, 2024

I've found a solution. That might not be the best syntax, but here's what I found.

from datetime import datetime
from fbchat import Client, get_json, now, ThreadsURL

class EchoBot(Client):

    def __init__(self,email, password, debug=True, user_agent=None):
        Client.__init__(self,email, password, debug, user_agent)
        self.friends = {}

    def on_message(self, mid, author_id, author_name, message, metadata):
        self.markAsDelivered(author_id, mid) #mark delivered
        self.markAsRead(author_id) #mark read

        name = self.friends.get(author_id, "unknown")
        print repr("{} said {}".format(name, message))

    def findFriends(self):
        timestamp = now()
        date = datetime.now()
        data = {
            'client' : self.client,
            'inbox[offset]' : 0,
            'inbox[limit]' :80,
        }

        r = self._post(ThreadsURL, data)
        if not r.ok or len(r.text) == 0:
            return None

        j = get_json(r.text)

        # Get friends' names
        for participant in j['payload']['participants']:
            self.friends[participant["fbid"]] = participant["name"]


bot = EchoBot("...", "...")
bot.findFriends()
bot.listen()
'''

The `findFriends` method is the same as `getThreadList`, at the beginning.  Where it defers is that the JSON response is used to create the dictionary of friends.  That may be worth adding in the `getThreadList` method itself.

from fbchat.

pirelle avatar pirelle commented on August 30, 2024

I've made a pull request, idea was taken from https://github.com/Schmavery/facebook-chat-api/blob/master/src/getFriendsList.js

from fbchat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.