-
-
Save minmaxdata/4efa303da3c026d7c44b0c063a512c33 to your computer and use it in GitHub Desktop.
undocumented twitter activity api
This file contains 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
# coding: utf-8 | |
import oauth2 as oauth | |
import json | |
CONSUMER_KEY = "yT577ApRtZw51q4NPMPPOQ" | |
CONSUMER_SECRET = "3neq3XqN5fO3obqwZoajavGFCUrC42ZfbrLXy5sCv8" | |
ACCESS_KEY = "" | |
ACCESS_SECRET = "" | |
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET) | |
access_token = oauth.Token(key=ACCESS_KEY, secret=ACCESS_SECRET) | |
client = oauth.Client(consumer, access_token) | |
# undocumented api form https://github.com/sferik/twitter/blob/master/lib/twitter/api/undocumented.rb | |
url = 'https://api.twitter.com//i/activity/by_friends.json' | |
response, data = client.request(url) | |
#print json.dumps(json.loads(data), indent=2) | |
get_name = lambda u: '@'+u['screen_name'] | |
join_name = lambda us: ', '.join(map(get_name, us)) | |
for i in json.loads(data): | |
print join_name(i['sources']), i['action'], ':' | |
if i['action'] == 'favorite': | |
for t in i['targets']: | |
print '----', get_name(t['user']), t['text'].encode('utf8') | |
elif i['action'] == 'follow': | |
print '----', join_name(i['targets']) | |
else: | |
raise Exception('unkown action') | |
This file contains 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
# coding: utf-8 | |
from rauth import OAuth1Session | |
CONSUMER_KEY = 'yT577ApRtZw51q4NPMPPOQ' | |
CONSUMER_SECRET = '3neq3XqN5fO3obqwZoajavGFCUrC42ZfbrLXy5sCv8' | |
ACCESS_KEY = '' | |
ACCESS_SECRET = '' | |
session = OAuth1Session(consumer_key=CONSUMER_KEY, | |
consumer_secret=CONSUMER_SECRET, | |
access_token=ACCESS_KEY, | |
access_token_secret=ACCESS_SECRET) | |
r = session.get('https://api.twitter.com/i/activity/by_friends.json') | |
data = r.json() | |
get_name = lambda u: '@'+u['screen_name'] | |
join_name = lambda us: ', '.join(map(get_name, us)) | |
for i in data: | |
print join_name(i['sources']), i['action'], ':' | |
if i['action'] == 'favorite': | |
for t in i['targets']: | |
print '----', get_name(t['user'])+':', t['text'].encode('utf8') | |
elif i['action'] == 'follow': | |
print '----', join_name(i['targets']) | |
else: | |
raise Exception('unkown action') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment