Comments (5)
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.
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.
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.
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.
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)
- File loading progress
- Can't listen() Error #1357005 HOT 3
- Login not work
- FBchatException solution HOT 1
- Could not find fb_dtsg
- Could not find any ServerJSDefine. Please report this, along with the data below HOT 1
- Note for others unable to login HOT 4
- Failed parsing MQTT data on /t_trace as JSON HOT 3
- Sending AudioAttachments doesn't work HOT 4
- Trouble Logging in Error and info included
- Can't Log in HOT 7
- Search contact by mobile phone number
- Module not found Error!
- Error when sending request: Got 500 response.
- Closed
- Screenshot (Mar 25, 2023 6:10:08 AM)
- how can it get all feeds and comments
- GraphQL error #3252001: Rate limit exceeded / None HOT 3
- Sendlocalfile isn't working
- Is fbchat dead? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fbchat.