├── fbnew.py ├── README.md └── fb.py /fbnew.py: -------------------------------------------------------------------------------- 1 | import fb 2 | 3 | token = "get token from graph explorer" 4 | 5 | facebook = fb.graph.api(token) 6 | 7 | #To publish to group 8 | facebook.publish(cat="feed", id="group Id", message="jai balayya") 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | FB-python 2 | ========= 3 | 4 | Use python facebook sdk and perform actions from command line 5 | 6 | Get access token from graph-api explorer https://developers.facebook.com/tools/explorer/ .Choose all the required permissions and get the access token. 7 | 8 | Run the fb.py python file from the command line 9 | 10 | 11 | 12 | For the new fbtry.py 13 | To setup download from https://pypi.python.org/pypi/fb/0.4.0 and run python setup.py install 14 | To get groupid from name use https://lookup-id.com/ 15 | -------------------------------------------------------------------------------- /fb.py: -------------------------------------------------------------------------------- 1 | 2 | import facebook 3 | 4 | 5 | 6 | 7 | import requests 8 | 9 | from time import strftime 10 | 11 | AFTER = "1392891447" 12 | import time 13 | 14 | import json 15 | 16 | token=""#Insert access token here. 17 | 18 | 19 | 20 | graph1 = facebook.GraphAPI(token) 21 | 22 | 23 | profile = graph1.get_object("me") 24 | friends = graph1.get_connections("me", "friends") 25 | graph1.put_object("me", "feed", message="I am writing on my wall!") 26 | tags = json.dumps([{'x':50, 'y':50, 'tag_uid':12345}, {'x':10, 'y':60, 'tag_text':'a turtle'}]) 27 | graph1.put_photo(open('Your photo in the same folder'), 'Look at this cool photo!', None, tags=tags) 28 | 29 | #Gets the posts on your wall 30 | 31 | def get_posts(): 32 | """Returns dictionary of id, first names of people who posted on my wall 33 | between start and end time""" 34 | 35 | query = ("SELECT post_id, actor_id, message FROM stream WHERE " 36 | "filter_key = 'others' AND source_id =me() AND " 37 | "created_time > " + AFTER + " LIMIT 200") 38 | 39 | payload = {'q': query, 'access_token': token} 40 | 41 | r = requests.get('https://graph.facebook.com/fql', params=payload) 42 | 43 | result = json.loads(r.text) 44 | 45 | return result 46 | 47 | #print get_posts() 48 | 49 | 50 | #Get posts in a group 51 | #data = graph1.get_object("Group id" + "/feed", page=False, retry=50, limit=800000000) 52 | #print data 53 | 54 | # Comment on a post in a group 55 | #graph1.put_object("Id of the post in the group", "comments", message="hehe") 56 | 57 | 58 | 59 | 60 | #r = requests.get('https://graph.facebook.com/%s' % wallpost['actor_id']) 61 | 62 | #Comments on all the wall posts 63 | def commentall(wallposts): 64 | """Comments thank you on all posts""" 65 | 66 | 67 | 68 | 69 | for wallpost in wallposts: 70 | r = requests.get('https://graph.facebook.com/%s' % 71 | wallpost['actor_id']) 72 | url = 'https://graph.facebook.com/%s/comments' % wallpost['post_id'] 73 | user = json.loads(r.text) 74 | #message = 'Thanks %s :)' % user['first_name'] 75 | message = 'Thanks %s :)' 76 | payload = {'access_token': token, 'message': message} 77 | 78 | s = requests.post(url, data=payload) 79 | print s 80 | 81 | print "Wall post %s done" % wallpost['post_id'] 82 | 83 | 84 | graph1.put_object("Id of the page you own", "feed", message="I am writing on my wall!")''' 85 | 86 | --------------------------------------------------------------------------------