Skip to content

Instantly share code, notes, and snippets.

@brianly
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianly/dffc4098805815d6c2d6 to your computer and use it in GitHub Desktop.
Save brianly/dffc4098805815d6c2d6 to your computer and use it in GitHub Desktop.
Iterate over the /api/v1/messages/sent.json endpoint and just return those for your user. Takes your user ID as input (can be automated.)
import sys
import time
import yampy
import webbrowser
def get_input(prompt):
if sys.hexversion > 0x03000000:
return input(prompt)
else:
return raw_input(prompt)
def list_sent_messages(token, from_id, count=0):
yammer = yampy.Yammer(access_token=token)
message_id = None
while True:
sent_messages = yammer.messages.sent(older_than=message_id)
for message in sent_messages.messages:
if message['sender_id'] == from_id:
print message['id']
print message['url']
print message['created_at']
print message['body']['plain']
print '----------------------------------------------'
print
last_item = sent_messages.messages[-1]
message_id = last_item['id']
time.sleep(15)
count += 1
if count == 20:
break
print('done')
def authorize():
authenticator = yampy.Authenticator(client_id='',
client_secret='')
redirect_uri = 'https://www.bing.com/'
auth_url = authenticator.authorization_url(redirect_uri)
webbrowser.open(auth_url)
code = get_input('Enter the code: ')
return authenticator.fetch_access_token(code)
if __name__ == "__main__":
# token = authorize()
# print token
token = ''
list_sent_messages(token, 123456)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment