fbchat
fbchat copied to clipboard
Unable to search for threads raising "#1675036 GraphQL Query Blocked"
Description of the problem
Unable to search for threads, I've been experiencing this error for an hour now while it was working before.
Code to reproduce
import fbchat as fb
from misc.session import get_session, save_cookies
session = get_session('email', 'password')
client = fb.Client(session=session)
print(next(client.search_for_threads('some user', limit=1)))
Traceback
Traceback (most recent call last):
File "lib\site-packages\fbchat\_client.py", line 152, in search_for_threads
(j,) = self.session._graphql_requests(
File "lib\site-packages\fbchat\_session.py", line 404, in _graphql_requests
return self._post("/api/graphqlbatch/", data, as_graphql=True)
File "lib\site-packages\fbchat\_session.py", line 372, in _post
return _graphql.response_to_json(r.text)
File "lib\site-packages\fbchat\_graphql.py", line 51, in response_to_json
_exception.handle_graphql_errors(value)
File "lib\site-packages\fbchat\_exception.py", line 128, in handle_graphql_errors
raise GraphQLError(
fbchat.GraphQLError: #1675036 GraphQL Query Blocked:
Environment information
- Python version 3.8.2
-
fbchat
version 2.0.0a2
No idea why it didn't work today, perhaps some new Facebook updates I guess. Any help?
I'm running into a similar issue when running
client.fetchThreadList()
Traceback
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/fbchat/_graphql.py", line 43, in response_to_json
j = json.loads(content, cls=ConcatJSONDecoder)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 361, in loads
return cls(**kw).decode(s)
File "/usr/local/lib/python3.7/site-packages/fbchat/_graphql.py", line 21, in decode
obj, end = self.raw_decode(s, idx=_w(s, end).end())
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/fbchat/_client.py", line 827, in fetchThreadList
(j,) = self.graphql_requests(_graphql.from_doc_id("1349387578499440", params))
File "/usr/local/lib/python3.7/site-packages/fbchat/_client.py", line 130, in graphql_requests
return tuple(self._state._graphql_requests(*queries))
File "/usr/local/lib/python3.7/site-packages/fbchat/_state.py", line 273, in _graphql_requests
return self._post("/api/graphqlbatch/", data, as_graphql=True)
File "/usr/local/lib/python3.7/site-packages/fbchat/_state.py", line 241, in _post
return _graphql.response_to_json(content)
File "/usr/local/lib/python3.7/site-packages/fbchat/_graphql.py", line 45, in response_to_json
Thanks for the report, this is most likely because we're using a custom GraphQL query that Facebook doesn't support anymore.
Which means we'll have to change it to use the same APIs as the search menu uses.
Initial research shows we could use:
params = {
"query": query,
"num_users": 10,
"num_groups": 8,
"num_pages": 5
}
(j,) = session._graphql_requests(_graphql.from_doc_id("2268911786543136", params))
With various configurations based on which search_for_X
method was called, and maybe combine it with:
params = {
"search_query": query,
"result_limit": 3,
"exclude_ids": [],
"context": "web_messenger_composer"
}
(j,) = session._graphql_requests(_graphql.from_doc_id("2706854202719826", params))
If we want to search within messages as well?
But theres quite a bit of work needed to do this, since we need to update our parsing methods to handle this new result
@madsmtm hello my freind how to get page, user info using graphql and what is the method to get the doc_id or query_id ??? help me please
The snippets I posted were just notes for myself when fixing this in the future - but I should probably add some documentation about what these Facebook GraphQL internals mean...