API called is made using the variable results:
results = service.users().messages().list(userId='me', labelIds=['INBOX', 'UNREAD']).execute()
A dictionary is returned:
{'messages': [{'id': '182f01f99c14b435', 'threadId': '182ef213b5174c23'}, {'id': '182f0120c66cc135', 'threadId': '182ef214b5174c23'}], 'resultSizeEstimate': 2}
Passing blank list and results into a function:
message_list = []
def return_message(message_list, results):
messages_ = results.get('messages', [])
for message in messages_:
for k,v in message.items():
message_list.append(message)
return message_list
Run the function but I am only able to return 1 appended message:
return_message(message_list, results)
print(message_list)
[{'id': '182f01f88c14b435', 'threadId': '182ef213b5154c23'}]
How do I return the entire results passed in at the beginning from the function so it's all been appended onto message_list?