So the result of this code is a list like this:
[
{'id': 'abcd', 'created_time': '2016-12-09T13:45:43+0000'},
{'id': 'efgh', 'created_time': '2016-12-09T07:47:54+0000'},
{'id': 'ijkl', 'created_time': '2016-12-09T07:47:34+0000'},
{'id': 'mnop', 'created_time': '2016-12-09T07:47:09+0000'},
{'id': 'qrst', 'created_time': '2016-12-09T07:46:52+0000'}
]]
and I'd like to get a list like:
ID
abcd
efgh
ijkl
mnop
qrst
I's appreciate any help as I'm pulling my hair out with this one!
def d_values(d, depth):
if depth == 1:
for i in d.values():
yield i
else:
for v in d.values():
if isinstance(v, dict):
for i in d_values(v, depth-1):
yield i
def Get_Message_IDs (Conversation_ID, Token):
Request = urllib.request.urlopen('https://graph.facebook.com/v2.8/' + Conversation_ID +'?fields=messages&access_token=' + Token)
ids = list()
try:
response = Request
output = response.read()
output = output.decode("utf-8")
output = ast.literal_eval(output)
output = list(d_values(output, 2))
print(output)
except Exception as exec:
print(exec)