Skip to content

Instantly share code, notes, and snippets.

@sokcuri
Forked from iHani/activity.py
Created February 13, 2023 00:19
Show Gist options
  • Save sokcuri/a0ac5d2d19fbec138339220cbe2ad50a to your computer and use it in GitHub Desktop.
Save sokcuri/a0ac5d2d19fbec138339220cbe2ad50a to your computer and use it in GitHub Desktop.
undocumented twitter activity api
# 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')
print
# 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')
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment