I'm currently learning to use the Facebook graph api
to retrieve a list of posts from groups. I've figured out how to get a valid request in and I know the response is correct, but unfortunately it's hard to inspect because one of the posts contains emoji - which are only found in unicode and I do not know how to deal with them.
Here's the more detailed setup:
response = graph.get_object(id=GROUP_ID, fields="feed")
Which is supposed to return a dictionary with all the elements, which ends up being a multilayered iterable. A dictionary contains a dictionary contains a list of the posts which are dictionaries and one of the posts has a message body that contains emoji.
Attempting to print the dictionary for inspection gives
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f605' in position 4323: character maps to
I've read another SO post that says I can pickle the dictionary; make it a string, then encode, then decode, then unpickle like so:
64_group = pickle.dumps(group).encode('base64', 'strict')
group = pickle.loads(utf8_group.decode('base64', 'strict'))
But that instead results in a new error (I tried to encode both utf-8 and base64, same result):
File "main.py", line 19, in <module>
utf8_group = pickle.dumps(group).encode('base64', 'strict')
AttributeError: 'bytes' object has no attribute 'encode'
How can I safely inspect and later work with these request results when they could potentially be of any level of nesting, and the unicode characters could be in any, all, or none of the levels? Is there a way to 'sanitize' my dictionary after it is returned so I can work with it's levels like normal?
If it helps, my eventual goal is to pull these into a sqlite or mysql database and serve them through php (I don't know javascript).