Created
December 15, 2015 16:24
-
-
Save brianly/89c4c4c383084d029e91 to your computer and use it in GitHub Desktop.
Repro of token issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yampy | |
import logging | |
import json | |
import time | |
from yampy.errors import ResponseError | |
import constants # protect my oauth token | |
# Enable this to dump HTTP-level info from yampy lib | |
# logging.basicConfig(level=logging.DEBUG) | |
def is_token_valid(token_metadata): | |
time.sleep(2) | |
yammer = yampy.Yammer(access_token=token_metadata['token']) | |
try: | |
current_user = yammer.messages.all()#users.find_current() | |
print 'Success on %s (NID: %s)' % (token_metadata['network_permalink'], token_metadata['network_id']) | |
return True | |
except ResponseError: | |
print 'Failure on %s (NID: %s)' % (token_metadata['network_permalink'], token_metadata['network_id']) | |
return False | |
# Kick off by initializing with a user's token from the | |
# server-side flow. This gives access to the home network. | |
yammer = yampy.Yammer(access_token=constants.ACCESS_TOKEN) | |
# Call the tokens.json endpoint and get a list of tokens | |
# for all other networks that user belongs to as a guest | |
# or EN member. | |
tokens = yammer.client.get("/oauth/tokens") | |
time.sleep(1) | |
# Go through the list of tokens and try to get info for the | |
# current user in each. Track failures and successes | |
successes = [] | |
failures = [] | |
for t in tokens: | |
result = is_token_valid(t) | |
if result == True: | |
successes.append(t) | |
else: | |
failures.append(t) | |
# Seeing quite a large number of failures | |
print 'Tokens from tokens.json:\t\t%s' % len(tokens) | |
print 'Successes:\t\t%s' % len(successes) | |
print 'Failures:\t\t%s' % len(failures) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment