Skip to content

Commit 368d928

Browse files
author
john joseph
committed
uploading files
1 parent 3edd846 commit 368d928

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

fb.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import requests
2+
import json
3+
4+
TOKEN = 'facebook token with permissions to post on wall stream'
5+
6+
def get_posts():
7+
"""Returns dictionary of id, first names of people who posted on my wall between start and end time"""
8+
query = ("SELECT post_id, actor_id, message FROM stream WHERE "
9+
"filter_key = 'others' AND actor_id!='#your_fb_id#' AND source_id = me()"
10+
"AND created_time = #start_timestamp# LIMIT 200")
11+
payload = {'q': query, 'access_token': TOKEN}
12+
r = requests.get('https://graph.facebook.com/fql', params=payload)
13+
result = json.loads(r.text)
14+
return result['data']
15+
16+
def commentall(wallposts):
17+
"""Comments thank you on all posts"""
18+
#TODO convert to batch request later
19+
20+
for wallpost in wallposts:
21+
r = requests.get('https://graph.facebook.com/%s' %
22+
wallpost['actor_id'])
23+
24+
url = 'https://graph.facebook.com/%s/comments' % wallpost['post_id']
25+
user = json.loads(r.text)
26+
message = 'Thanks %s :)' % user['first_name']
27+
payload = {'access_token': TOKEN, 'message': message}
28+
29+
s = requests.post(url, data=payload)
30+
print "Wall post %s done" % wallpost['post_id']
31+
32+
if __name__ == '__main__':
33+
commentall(get_posts())
34+

0 commit comments

Comments
 (0)