-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfbgroupposter.py
More file actions
44 lines (35 loc) · 1.41 KB
/
fbgroupposter.py
File metadata and controls
44 lines (35 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
import json
import sys
"""
To get the access token goto http://graph.facebook.com/tools/explorer
With "Get Access Token" option select "user_group" and "Friend_group" in "User Data Permissions" and "Friends Data Permissions"
"""
TOKEN = '' #Insert access token here.
# Collects all group names and group id from the user which he belongs to
def get_groups():
query = (
"SELECT gid,name FROM group where gid in ( SELECT gid FROM group_member WHERE uid=me())"
)
payload = {'q': query, 'access_token': TOKEN}
response = requests.get('https://graph.facebook.com/fql', params=payload)
result = json.loads(response.text)
return result['data']
# Post feeds to all the groups
def post_status(name):
message = raw_input("Enter your message to be posted:")
for i in name:
try:
prompt = u"Want to post in %s?(Y/N) " % i['name']
check = raw_input(prompt.encode(sys.stdout.encoding))
except UnicodeError:
continue
if ((check == 'N') | (check == 'n')):
continue
post_data = {'access_token': TOKEN, 'message': message}
url = 'https://graph.facebook.com/%s/feed' % str(i['gid'])
response = requests.post(url, data=post_data)
print "Successfully posted in %s" % i['name']
if __name__ == '__main__':
post_status(get_groups())
# To run the script "python group_post.py"