Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Created January 29, 2014 20:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save fmasanori/8696746 to your computer and use it in GitHub Desktop.
Save fmasanori/8696746 to your computer and use it in GitHub Desktop.
Thanking my 500+ friends who wished me on my birthday on Facebook, by by Akshit Khurana
import requests
import json
AFTER = 1353233754
TOKEN = ' <insert token here> '
#by Akshit Khurana
def get_posts():
"""Returns dictionary of id, first names of people who posted on my wall
between start and end time"""
query = ("SELECT post_id, actor_id, message FROM stream WHERE "
"filter_key = 'others' AND source_id = me() AND "
"created_time > 1353233754 LIMIT 200")
payload = {'q': query, 'access_token': TOKEN}
r = requests.get('https://graph.facebook.com/fql', params=payload)
result = json.loads(r.text)
return result['data']
def commentall(wallposts):
"""Comments thank you on all posts"""
#TODO convert to batch request later
for wallpost in wallposts:
r = requests.get('https://graph.facebook.com/%s' %
wallpost['actor_id'])
url = 'https://graph.facebook.com/%s/comments' % wallpost['post_id']
user = json.loads(r.text)
message = 'Thanks %s :)' % user['first_name']
payload = {'access_token': TOKEN, 'message': message}
s = requests.post(url, data=payload)
print "Wall post %s done" % wallpost['post_id']
if __name__ == '__main__':
commentall(get_posts())********
@licensed
Copy link

Amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment