-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathget_messages.py
33 lines (28 loc) · 975 Bytes
/
get_messages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from freelancersdk.session import Session
from freelancersdk.resources.messages.messages import get_messages
from freelancersdk.resources.messages.exceptions import \
MessagesNotFoundException
from freelancersdk.resources.messages.helpers import create_get_messages_object
import os
def sample_get_messages():
url = os.environ.get('FLN_URL')
oauth_token = os.environ.get('FLN_OAUTH_TOKEN')
session = Session(oauth_token=oauth_token, url=url)
query = create_get_messages_object(
threads=[
80034553,
102,
],
user_details=True
)
try:
messages = get_messages(session, query)
except MessagesNotFoundException as e:
print('Error message: {}'.format(e.message))
print('Server: response: {}'.format(e.error_code))
return None
else:
return messages
result = sample_get_messages()
if result:
print('Found messages: {}'.format(len(result['messages'])))