def fetch(url): result = fbconsole.get(url) if 'paging' in result: return list(fbconsole.iter_pages(result)) if 'data' in result: return result['data'] return result
def handle(self, *args, **options): if not os.path.isdir(TEMP_DIR): os.makedirs(TEMP_DIR, 0o700) self.stdout.write("Loading data from Facebook...") fbconsole.authenticate() # Use fbconsole.logout() to log out # Retrieve user data user = fbget_user() self.stdout.write("User '{name}', ID {id}, username {username}".format(**user)) # Load accounts cache cache = {user['id']: user} for filename in glob.glob(os.path.join(PROFILE_DIR, '*.json')): profile = load_data(filename) if not profile or 'id' not in profile: self.stderr.write("Nothing loaded in file '{0}'".format(filename)) cache[profile['id']] = profile if len(cache) > 1: print("Loaded {0} profiles from cache".format(len(cache))) # Enumerate friends for friend in fbconsole.iter_pages(fbconsole.get('/me/friends')): fid = friend['id'] fname = friend['name'].encode('ascii', 'replace') if fid not in cache: self.stdout.write("Retrieve profile of {0}, (ID={1})".format(fname, fid)) profile = fbconsole.get('/' + fid) if profile['id'] != fid: self.stderr.write("{0} has two IDs: {1} and {2}".format(fname, fid, profile['id'])) save_data(os.path.join(PROFILE_DIR, profile['id'] + '.json'), profile) cache[profile['id']] = profile self.stdout.write(".. done")
def newsFeed(self, speech, language): statuses = 15 #how many statuses you want to fetch limit = 0 error = 0 if (language == "de-DE"): statusString = "" view = AddViews(self.refId, dialogPhase="Completion") self.say("Ich checke ...") for post in fbconsole.iter_pages(fbconsole.get('/me/home')): if(error == 1): error = 0 else : limit = limit + 1 try: post['message'] ansewer = post['from']['name'] + " schrieb : " + post['message'] print "INFO Getting status : ", limit statusString = statusString + ansewer + "\n\n" #self.say(ansewer) except KeyError as (strerror): #print "Key error({0})".format(strerror) error = 1 continue if(limit == statuses): break facebookStatuses = AnswerObject(title='Statuses :',lines=[AnswerObjectLine(text=statusString)]) view1 = 0 view1 = AnswerSnippet(answers=[facebookStatuses]) view.views = [view1] self.sendRequestWithoutAnswer(view) self.complete_request()
def get_fb_search_result_list(graph, query_word, query_type): # query_type # user # 搜尋用戶(如果用戶允許搜尋名稱)。 # 名稱。 # # page # 搜尋粉絲專頁。 # 名稱。 # # event # 搜尋活動。 # 名稱。 # # group # 搜尋社團。 # 名稱。 # # place # 搜尋地標。您可以新增 center 參數(含經緯度)和選用的 distance 參數(以公尺計),將搜尋範圍縮小至特定地點和距離: # 名稱。 # # placetopic # 傳回可能的地標粉絲專頁主題和編號的清單。使用 topic_filter=all 參數以取得完整清單。 # 無。 # # ad_* # 不同搜尋選項的集合,可用於找出目標設定選項。 # 請參閱目標設定選項文件 search_result = graph.request('/search?', {'q':query_word, 'type':query_type, 'limit':25}) search_list = list(fbconsole.iter_pages(search_result)) return search_list
def get_feed_list(graph, page_id, feed_limit): feed_list = graph.get_object(page_id + '/feed') tmp_list = [] tmp_count = 0 for feed in fbconsole.iter_pages(feed_list): tmp_list.append(feed) tmp_count += 1 if (tmp_count > feed_limit): break return tmp_list
def get_posts(self, days=3): day = datetime.datetime.now().day for post in fb.iter_pages(fb.get('/me/feed')): d, m, y = get_date_from_post(post) if day - d > days: break else: yield post
def get_comment_list(graph, feed_msg_id, comment_limit): feed_comment_list = graph.get_object(feed_msg_id + '/comments') tmp_list = [] tmp_count = 0 for comment in fbconsole.iter_pages(feed_comment_list): tmp_list.append(comment) tmp_count += 1 if (tmp_count > comment_limit): break return tmp_list
def get_feed_list(graph, page_id, feed_limit): feed_list = graph.get_object(page_id+'/feed') tmp_list = [] tmp_count = 0 for feed in fbconsole.iter_pages(feed_list): tmp_list.append(feed) tmp_count += 1 if (tmp_count > feed_limit): break return tmp_list
def GroupGenerator(): file = open('groupset', mode='w', encoding='utf-8') GroupCount = 0 GroupSet = graph.get_object('me/groups') for group in fbconsole.iter_pages(GroupSet): GroupPrivacy = group['privacy'] GroupId = group['id'] GroupName = group['name'] # print(GroupId + " , " + GroupName) line = (GroupId + "," + GroupName + "\n") GroupCount += 1 file.write(line) print("total %s groups be generated\n" % (GroupCount)) file.close()
def GroupGenerator(): file = open('groupset', mode = 'w', encoding = 'utf-8') GroupCount = 0 GroupSet = graph.get_object('me/groups') for group in fbconsole.iter_pages(GroupSet): GroupPrivacy = group['privacy'] GroupId = group['id'] GroupName = group['name'] # print(GroupId + " , " + GroupName) line = (GroupId + "," + GroupName + "\n") GroupCount += 1 file.write(line) print("total %s groups be generated\n" %(GroupCount)) file.close()
def facebookFriends(self, speech, language): if (language == "de-DE"): AnswerString = "" view = AddViews(self.refId, dialogPhase="Completion") fbconsole.AUTH_SCOPE = ['publish_stream', 'publish_checkins', 'read_stream', 'offline_access'] fbconsole.authenticate() for post in fbconsole.iter_pages(fbconsole.get('/me/friends')): AnswerString = AnswerString + post['name'] + "\n" self.say("Das sind deine Freunde:") FacebookFriends = AnswerObject(title='Deine Freunde :',lines=[AnswerObjectLine(text=AnswerString)]) view1 = 0 view1 = AnswerSnippet(answers=[FacebookFriends]) view.views = [view1] self.sendRequestWithoutAnswer(view) self.complete_request()
def newsFeed(self, speech, language): statuses = 10 #how many statuses you want to fetch limit = 0 error = 0 if (language == "en-US"): for post in fbconsole.iter_pages(fbconsole.get('/me/home')): if(error == 1): error = 0 else : limit = limit + 1 try: post['message'] ansewer = post['from']['name'] + " wrote : " + post['message'] print ansewer self.say(ansewer) except KeyError as (strerror): #print "Key error({0})".format(strerror) error = 1 continue if(limit == statuses): break
def get_fb_search_result_list(graph, query_word, query_type): # query_type # user # 搜尋用戶(如果用戶允許搜尋名稱)。 # 名稱。 # # page # 搜尋粉絲專頁。 # 名稱。 # # event # 搜尋活動。 # 名稱。 # # group # 搜尋社團。 # 名稱。 # # place # 搜尋地標。您可以新增 center 參數(含經緯度)和選用的 distance 參數(以公尺計),將搜尋範圍縮小至特定地點和距離: # 名稱。 # # placetopic # 傳回可能的地標粉絲專頁主題和編號的清單。使用 topic_filter=all 參數以取得完整清單。 # 無。 # # ad_* # 不同搜尋選項的集合,可用於找出目標設定選項。 # 請參閱目標設定選項文件 search_result = graph.request('/search?', { 'q': query_word, 'type': query_type, 'limit': 25 }) search_list = list(fbconsole.iter_pages(search_result)) return search_list
import fbconsole CLIENT_ID = '534039770107244' CLIENT_SECRETS = '27b30f0ea6204f63feefd41efb8b384c' # fbAuth = fbauth.TokenHandler(CLIENT_ID, CLIENT_SECRETS) # access_token = fbAuth.get_access_token() access_token = 'CAACEdEose0cBABndlSSz81nHMnDmwkqRsx3G0EJWVWxmT1sCgiXIInZAWfX8RuUJBgE79YEKGScRNmFhiIMe41uZCAb45GpfUoesgI7OYFkebwzZAiSUGG1rmpBVIwQ3mtPAbCnZAVWodVBhaUZCbLongLZBDZAkmZBL1VdmbntQvZA8FAWplegVm3ewtyUWyIikLVIb6ogrXiv9ClCev0sK4' graph = facebook.GraphAPI(access_token, version='2.3') me = graph.get_object('me') data = graph.request('search', {'q': 'free', 'type': 'group'}) for p in fbconsole.iter_pages(data): print(p) # permissions = graph.get_object('me/permissions') # print(permissions) # version = graph.get_version() # print(version) # SearchRes = graph.request('search', {'q':'free', 'type':'group'}) # print(SearchRes) # graph.put_object('me', 'feed', message = 'test') # res = graph.put_wall_post(message="test", attachment = {'link':'http://beefun01.com/p/2263/'}, profile_id = '1444846532463984') # print(res)
priority = 1, ) return #access_token= '<access-token>' #graph = GraphAPI(access_token) #fbconsole.ACCESS_TOKEN = access_token fbconsole.AUTH_SCOPE = ['publish_stream', 'publish_checkins','publish_actions','manage_notifications','read_stream','read_mailbox','user_posts','public_profile'] fbconsole.authenticate() with open(".fb_access_token") as json_file: json_data = json.load(json_file) atoken = json_data['access_token'] graph = GraphAPI(atoken) #userdata = fbconsole.get('/me') #print("Hi "+userdata['first_name']) count=0 while True: count=count+1 show_message("Script running times: " + str(count)) for notific in fbconsole.iter_pages(fbconsole.get('/me/notifications')): show_message(notific['title'].encode('utf-8')) graph.post( path = notific['id'], unread = 0 ) sleep(60)
if ('link' in raw['data'][0]['story']): activity_link = raw['data'][0]['link'] elif ('message' in raw['data'][0]): activity = raw['data'][0]['message'] activity_person = raw['data'][0]['from']['name'] if ('link' in raw['data'][0]['message']): activity_link = raw['data'][0]['link'] elif ('picture' in raw['data'][0]): activity = raw['data'][0]['picture'] activity_person = raw['data'][0]['from']['name'] if ('link' in raw['data'][0]['story']): activity_link = raw['data'][0]['link'] total = 0 # Count for number of posts for post in fbconsole.iter_pages(graph.get_object('/'+name+'/feed')): # Iterates over the feed and retrieves posts if ('message' in post): # Makes sure it is a post and not a 'like', comment etc. total += 1 if (post['message'] != activity): print total,':', post['updated_time'], '\n', post['message'], '\n' # Prints posts if total > 0: break # Limits to three, change 2-> 4 if you want the last 5 posts etc. print activity, 'From', activity_person if (activity_link != ''): print 'Click for link:', activity_link last_activity.close() link.close() f.close()
import fbconsole import sys fbconsole.AUTH_SCOPE = ['friends_about_me', 'friends_likes'] fbconsole.authenticate() for url in sys.argv[1:]: print list(fbconsole.iter_pages(fbconsole.get(url)))
print(raw['data'][0]['picture']) print(raw['data'][0]['from']['name']) last_activity.write(raw['data'][0]['picture'].encode('utf8')+'\n') last_activity.write(raw['data'][0]['from']['name'].encode('utf8')+'\n') link.write(raw['data'][0]['link'].encode('utf8')+'\n') except KeyError: print(raw['data'][0]['from']['name']) last_activity.write(raw['data'][0]['from']['name'].encode('utf8')+'\n') #shutil.move('last_activity.txt', newpath ) #shutil.move('link.txt', newpath ) graph = facebook.GraphAPI(token) # Grants access total = 0 # Count for number of posts for post in fbconsole.iter_pages(graph.get_object('/callumkift/feed')): # Iterates over the feed and retrieves posts if ('message' in post): # Makes sure it is a post and not a 'like', comment etc. total += 1 print total,':', post['updated_time'], '\n', post['message'], '\n' # Prints posts if total > 2: break # Limits to three, change 2-> 4 if you want the last 5 posts etc. last_activity.close() link.close() f.close() t.close()
subFolder="home" elif sys.argv[3] == 'h': subFolder="home" elif sys.argv[3] == 'm': subFolder="feed" else: subFolder="home" #==== input control ==== if sys.argv[1] == 'p': status = fbconsole.post("/me/feed", {"message":sys.argv[2]}) elif sys.argv[1] == 'r': for post in fbconsole.iter_pages(fbconsole.get('/me/'+subFolder)): #==== MESSAGE ==== print '' dedented_text = textwrap.dedent(post.get('message',defMsgs)).strip() print colorstr(textwrap.fill(dedented_text,width=40, initial_indent=' '+post.get('from',defMsgs).get('name',defMsgs)+":", subsequent_indent=' '),'YELLOW') #print post.get('comments',defComments) #print len(post.get('comments',defComments)) #print post.get('comments',defComments) if post.get('comments',defComments).get('count',defMsgs) != 0: #==== PICTURE ==== if post.get('picture',defPic)!='no pic': #paraList = [' ','--term-width','--colors',post.get('picture',defPic)] #run('jp2p',paraList) paraList = [' ',post.get('picture',defPic),'-s','-o','tmp.jpg'] print paraList run('curl',paraList);
def get_fb_groups(graph): groups = graph.get_object('/me/groups') group_list = list(fbconsole.iter_pages(groups)) # group_list_hookfunction(group_list) return group_list
accounts = graph.get_object('/me/accounts') page_token = accounts['data'][0]['access_token'] return page_token def get_fb_page_graph_instance(username, password): page_token = get_fb_page_token(username, password) page_graph = facebook.GraphAPI(page_token) return page_graph def current_time(): return '[' + (datetime.now()).strftime('%Y/%m/%d %H:%M:%S') + ']' username = '******' password = '******' art_start_no = 3210 art_end_no = 3425 page_token = get_fb_page_token(username, password) page_graph = facebook.GraphAPI(page_token) dobee01_id = '1020239824709036' feed_datas = page_graph.get_object(dobee01_id+'/feed') for each_feed in fbconsole.iter_pages(feed_datas): feed_id = each_feed['id'] print(feed_id) page_graph.delete_object(id=feed_id)
def info(fb_id): result = '' result_post = '' # AUTHENTICATION OF USER - START token = authentication.AUTHENTICATE() # AUTHENTICATION OF USER - END graph = facebook.GraphAPI(token) name = str(fb_id) r = requests.get("https://graph.facebook.com/" + name + "/posts/" + '?access_token=' + token) # get the json file for the feed raw = json.loads(r.text) activity = '' activity_person = '' activity_link = '' today = datetime.datetime.now() two_weeks = 14 # 14 days for two weeks, because the time difference is now taken in days print '\n\n' if len(raw) > 1 : what = raw['data'][0] # Only get the first data entry, since we are only interested in that if ('story' in what): activity = raw['data'][0]['story'] #+ '\n' + raw['data'][0]['description'] activity_person = raw['data'][0]['from']['name'] updated_time_activity = what['updated_time'] if ('link' in what): activity_link = raw['data'][0]['link'] elif ('message' in what): activity = raw['data'][0]['message'] activity_person = raw['data'][0]['from']['name'] updated_time_activity = what['updated_time'] if ('link' in what): activity_link = raw['data'][0]['link'] elif ('picture' in what): activity = raw['data'][0]['picture'] activity_person = raw['data'][0]['from']['name'] updated_time_activity = what['updated_time'] if ('link' in what): activity_link = raw['data'][0]['link'] activity_time = datetime.datetime.strptime(updated_time_activity,'%Y-%m-%dT%H:%M:%S+0000') act_time = str(activity_time) delta = today - activity_time if delta.days < two_weeks: # taking the difference in days -> delta.days is an interger! if (activity != ''): result = activity + ' Posted by ' + activity_person + ' Date: ' + updated_time_activity # print 'Latest activity:' # print activity, 'From', activity_person # print 'Date:', updated_time_activity if (activity_link != ''): #result = result + 'Click for link: ' + activity_link result_link = activity_link #print 'Click for link:', activity_link else: result = 'No activity in the last two weeks. Last activity on ' + act_time result_link = '' else: result = 'No recorded activity.' result_link = '' total = 0 # Count for number of posts for post in fbconsole.iter_pages(graph.get_object('/'+name+'/feed')): # Iterates over the feed and retrieves posts post_time = datetime.datetime.strptime(post['updated_time'],'%Y-%m-%dT%H:%M:%S+0000') delta = today - post_time if delta.days < two_weeks: # taking the difference in days -> delta.days is an interger! if ('message' in post): # Makes sure it is a post and not a 'like', comment etc. total += 1 if (post['message'] != result): result_post = 'Latest wall post: ' + post['updated_time'] + ' ' + post['message'] + ' ' + 'From ' + post['from']['name'] result_post_link = post['link'] #print post['updated_time'], '\n', post['message'], '\n' , 'From', post['from']['name'], '\n'# Prints posts if total > 0: break # Limits to three, change 2-> 4 if you want the last 5 posts etc. else: result_post = 'No wall posts in the last two weeks.' result_post_link = '' break return (result, result_post, result_link, result_post_link)
CLIENT_ID = '534039770107244' CLIENT_SECRETS = '27b30f0ea6204f63feefd41efb8b384c' # fbAuth = fbauth.TokenHandler(CLIENT_ID, CLIENT_SECRETS) # access_token = fbAuth.get_access_token() access_token = 'CAACEdEose0cBABndlSSz81nHMnDmwkqRsx3G0EJWVWxmT1sCgiXIInZAWfX8RuUJBgE79YEKGScRNmFhiIMe41uZCAb45GpfUoesgI7OYFkebwzZAiSUGG1rmpBVIwQ3mtPAbCnZAVWodVBhaUZCbLongLZBDZAkmZBL1VdmbntQvZA8FAWplegVm3ewtyUWyIikLVIb6ogrXiv9ClCev0sK4' graph = facebook.GraphAPI(access_token, version='2.3') me = graph.get_object('me') data = graph.request('search', {'q':'free', 'type':'group'}) for p in fbconsole.iter_pages(data): print(p) # permissions = graph.get_object('me/permissions') # print(permissions) # version = graph.get_version() # print(version) # SearchRes = graph.request('search', {'q':'free', 'type':'group'}) # print(SearchRes) # graph.put_object('me', 'feed', message = 'test') # res = graph.put_wall_post(message="test", attachment = {'link':'http://beefun01.com/p/2263/'}, profile_id = '1444846532463984') # print(res)
accounts = graph.get_object('/me/accounts') page_token = accounts['data'][0]['access_token'] return page_token def get_fb_page_graph_instance(username, password): page_token = get_fb_page_token(username, password) page_graph = facebook.GraphAPI(page_token) return page_graph def current_time(): return '[' + (datetime.now()).strftime('%Y/%m/%d %H:%M:%S') + ']' username = '******' password = '******' art_start_no = 3210 art_end_no = 3425 page_token = get_fb_page_token(username, password) page_graph = facebook.GraphAPI(page_token) dobee01_id = '1020239824709036' feed_datas = page_graph.get_object(dobee01_id + '/feed') for each_feed in fbconsole.iter_pages(feed_datas): feed_id = each_feed['id'] print(feed_id) page_graph.delete_object(id=feed_id)
""" import fbconsole import sys import json import time fbconsole.logout() fbconsole.authenticate() allContent = [] i = 0 for post in fbconsole.iter_pages(fbconsole.get('/119600664905706/feed', {'limit':5})): if 'message' in post: thisLine = "\n" dateTime = post['created_time'].encode('utf8').split('T') thisLine = thisLine + dateTime[0] thisLine = thisLine +'\t' + dateTime[1].replace('+0000', '') thisLine = thisLine +'\t' + post['message'].encode('utf8').replace('\n', ' ') thisLine = thisLine +'\t' + post['from']['id'].encode('utf8')+'\t'+post['from']['name'].encode('utf8').replace('\n', ' ')