def commentlikepost(post_limit): ''' Likes and comments post ''' fbconsole.AUTH_SCOPE = ['publish_stream', 'publish_checkins', 'read_stream'] fbconsole.authenticate() #status = fbconsole.post('/me/feed', {'message':'Hello from python s script'}) fbconsole.authenticate() query = fbconsole.fql("SELECT actor_id, post_id FROM stream WHERE source_id=me() LIMIT %s" % post_limit) print query for post in query: r = requests.get('https://graph.facebook.com/%s' % post['actor_id']) user = json.loads(r.text) comment = '%s %s: Like and comment from python script! :)' % (user['first_name'] , user['last_name']) print comment #Reply comment comment_id = requests.post("https://graph.facebook.com/" + str(post['post_id']) + "/comments/?access_token=" + fbconsole.ACCESS_TOKEN + "&message=%s" % comment ) print "Comment id: " + comment_id.text #Like the post requests.post("https://graph.facebook.com/" + str(post['post_id']) + "/likes/?access_token=" + fbconsole.ACCESS_TOKEN + "&method=POST") print "Liked" fbconsole.logout()
def bdaythank(post_limit, comment=None): ''' Likes and comments all posts automatically ''' fbconsole.AUTH_SCOPE = [ 'publish_actions', 'read_stream', 'user_actions.news', 'publish_stream' ] fbconsole.authenticate() query = fbconsole.fql( "SELECT post_id FROM stream WHERE source_id=me() LIMIT %s" % post_limit) for post in query: if comment: comment_id = requests.post("https://graph.facebook.com/" + str(post['post_id']) + "/comments/?access_token=" + fbconsole.ACCESS_TOKEN + "&message=%s" % comment) print "Comment id: " + comment_id.text requests.post("https://graph.facebook.com/" + str(post['post_id']) + "/likes/?access_token=" + fbconsole.ACCESS_TOKEN + "&method=POST") print "$ Liked" fbconsole.logout()
def post(self): result = flask.request.form['expression'] status = fbconsole.post('/me/feed', {'message':result}) likes = fbconsole.get('/'+status['id']+'/likes') flask.flash(result) fbconsole.logout() return self.get()
def updateFacebookStatus(status): # fb.APP_ID = FACEBOOK_ID fb.AUTH_SCOPE = ["publish_stream"] fb.authenticate() fb.post("/crimson.beacon/feed", {"message": status}) fb.logout()
def index_page(): """This takes care fo the index page before and after facebook authentication Also, takes care of facebook authentication using fbconsole""" global SUBMIT_TITLE global FACEBOOK_VAL global PARAMS global FRIENDS if SUBMIT_TITLE: """IF at the submition page clear the filter parmeters and clear list of Friends""" PARAMS={'male':False,'female':False,'relationship':False,'single':False} FRIENDS={} if not FACEBOOK_VAL: """If not facebook Validated initalize facebook authentication""" fbconsole.APP_ID="316500388373772" fbconsole.AUTH_SCOPE= ['friends_relationships'] fbconsole.authenticate() FACEBOOK_VAL=True """render submition page to see""" return render_template('submit.html') else: """if neither facebook authticated or at the submition page render the initial facebook initilaztion page""" fbconsole.logout() SUBMIT_TITLE=True return render_template('index.html')
def updateFacebookStatus(status): # fb.APP_ID = FACEBOOK_ID fb.AUTH_SCOPE = ['publish_stream'] fb.authenticate() fb.post('/crimson.beacon/feed', {'message': status}) fb.logout()
def fb_access(): """ logs into Facebook account and asks for permission. Further the music names are extracted from the profile""" fbconsole.AUTH_SCOPE = ['user_likes','publish_checkins' ] fbconsole.authenticate() music = fbconsole.fql("SELECT music FROM user WHERE uid=me()") music_names(music) fbconsole.logout()
def __del__(init): fb.logout()
def __del__(self): fb.logout()
import fbconsole as fb import shutil # for moving files fb.APP_ID = '741896972509458' #if you face error then reinstall fbconsole or logout fb.AUTH_SCOPE = ['publish_stream','publish_actions','manage_pages','photo_upload','user_photos'] fb.logout() #helps to update token by deleting it. fb.authenticate() #tokens = [] pnames = [] for i in range(len(fb.get('/me/accounts')['data'])): #tokens.append(fb.get('/me/accounts')['data'][i]['access_token']) pnames.append(fb.get('/me/accounts')['data'][i]['name']) for i in range(len(pnames)): print i,': ',pnames[i] pageno = input('Enter page no.') print 'Accessing ',pnames[pageno] fb.ACCESS_TOKEN = fb.get('/me/accounts')['data'][pageno]['access_token'] #ACCESS_TOKEN = get('/me/accounts')['data'][0]['access_token'] #print fb.ACCESS_TOKEN #print fb.get('/me')
sys.stdout = sys.__stdout__ sys.stderr.write(mystdout.getvalue()) connectors = [ "accounts", "activities", "adaccounts", "albums", "apprequests", "books", "checkins", "events", "family", "feed", "friendlists", "friendrequests", "friends", "games", "groups", "home", "inbox", "interests", "likes", "links", "locations", "messagingfavorites", "movies", "music", "mutualfriends", "notes", "notifications", "outbox", "payments", "permissions", "photos", "picture", "posts", "scores", "statuses", "tagged", "television", "updates", "videos" ] fb_data = fbconsole.get("/me") for connector in connectors: sys.stderr.write("Loading: " + connector + "\t") try: connected_data = fbconsole.get("/me/" + connector) fb_data[connector] = connected_data sys.stderr.write("success\n") except urllib2.HTTPError: sys.stderr.write("HTTPError: Maybe permissions\n") except ValueError: sys.stderr.write("ValueError: Probably not decodable to JSON\n") fbconsole.logout() print json.dumps(fb_data, sort_keys=True, indent=4)
# this has to be done because there's an API limitation of max 100 photos! print "==> Fetching first 100 photos first!" photos = fbconsole.get('/'+album['id']+'/photos', {'limit':1000}) for ii, photo in enumerate(photos.get('data', [])): photo_name = '%s-%s' % (album.get('name'), ii) photo_path = os.path.join(album_dirname, photo_name+'.jpg') if not os.path.exists(photo_path): handle_photo(photo, photo_name) date = raw_input("Please enter the date of the 100th photo: ") # example: "1 january 2012" photos = fbconsole.get('/'+album['id']+'/photos', {'until':date, 'limit':1000}) print "###############################################################################" print "==> Now fetching remaining " + str(len(photos.get('data', []))) + " photos." for ii, photo in enumerate(photos.get('data', [])): photo_name = '%s-%s' % (album.get('name'), ii+100) photo_path = os.path.join(album_dirname, photo_name+'.jpg') if not os.path.exists(photo_path): handle_photo(photo, photo_name) else: photos = fbconsole.get('/'+album['id']+'/photos', {'limit':1000}) for ii, photo in enumerate(photos.get('data', [])): photo_name = '%s-%s' % (album.get('name'), ii) photo_path = os.path.join(album_dirname, photo_name+'.jpg') if not os.path.exists(photo_path): handle_photo(photo, photo_name) global_date_file.close() print "All Done!" fbconsole.logout()
def print1(): horoscope1(moon_sign) horoscope2(moon_sign) horoscope3(moon_sign) while True: try: moon_sign = raw_input("Your moon sign : ").lower() print1() #Posting on fb import fbconsole as fb fb.AUTH_SCOPE = ['public_profile', 'user_friends', 'manage_pages'] fb.APP_ID = '738141636393999' fb.authenticate() fb.post('/me/feed/', {'message': 'Today\'s Horoscope : ' + moon_sign + '\n\n' + a}) fb.post('/me/feed/', {'message': 'Today\'s Horoscope : ' + moon_sign + '\n\n' + c}) fb.post('/me/feed/', {'message': 'Today\'s Horoscope : ' + moon_sign + '\n\n' + d}) fb.logout() break except urllib2.HTTPError: print "Entered sign is incorrect.Please enter coorect one" time.sleep(1)
def logout(self): fbconsole.logout()
# -*- coding: UTF-8 -*- # importa a biblioteca para o delay from time import sleep # importa a biblioteca fbconsole import fbconsole as fb # importa a biblioteca para a comunicacao serial import serial try: fb.logout() except: pass # permissao e autenticacao do facebook fb.AUTH_SCOPE = ['publish_stream', 'publish_checkins'] fb.authenticate() # post a ser analisado id_user = '******' id_post = '756280991121834' post = {'id': '%s_%s' %(id_user, id_post)} #post = fb.post('/me/feed', {'message':'Olá, esta é uma mensagem automática enviada via Python'}) #post = fb.post('/me/photos', {'source':open('foto.jpg')}) # endereco da porta serial port = '/dev/ttyUSB0' # substitua por 'COM3' (Windows), ou '/dev/tty.usbmodem1d11' (Mac) - por exemplo # velocidade bps = 9600 # inicializa a porta serial
''' Script to export facebook contacts to a CSV based on the fbconsole tool ''' import fbconsole as fb import json,csv fb.AUTH_SCOPE=['friends_education_history','friends_location','friends_work_history'] fb.authenticate() friends=fb.fql("select uid,first_name,last_name,locale,affiliations,contact_email,email,current_address, current_location,birthday,friend_count,mutual_friend_count,hometown_location,languages,name,sex, website,education,work from user where uid in (select uid2 from friend where uid1=me())") #uids=[i['uid'] for i in friends] with open('fb_friends.json','w') as ofile: json.dump(friends,ofile) fb.logout() #destroy locally stored auth token names=[(i['first_name'],i['last_name']) for i in friends] with open('fb_names2012.csv','w') as ofile: writer=csv.writer(ofile) writer.writerow(('First Name','Last Name')) for name in names: try: writer.writerow(name) except UnicodeEncodeError: print('Name %s %s could not be written to CSV'%name)
# import fbconsole as Facebook # Facebook.APP_ID=APP_ID # #Facebook.ACCESS_TOKEN=SECRET_KEY # Facebook.AUTH_SCOPE=['publish_stream'] # Facebook.authenticate() # Facebook.post('/me/feed',{'message':statusmsg}) # Facebook.logout() import fbconsole as Facebook APP_ID='256039541189094' SECRET_KEY='cf28017ad90f5ed612c8282f9c9e07c1' GRANT_TYPE='client_credentials' AUTH_SCOPE='publish_stream' REDIRECT_URL='http://127.0.0.1:8080' access_token_url='https://graph.facebook.com/oauth/access_token?client_id=%s&client_secret=%s&grant_type=%s&scope=%s'%(APP_ID,SECRET_KEY,GRANT_TYPE,AUTH_SCOPE) print access_token_url import urllib res=urllib.urlopen(access_token_url) ACCESS_TOKEN=res.read() print ACCESS_TOKEN ACCESS_TOKEN=ACCESS_TOKEN.split('=')[1] Facebook.ACCESS_TOKEN=ACCESS_TOKEN Facebook.AUTH_SCOPE=[AUTH_SCOPE] Facebook.post('/me/feed',{'message':statusmsg}) Facebook.logout()
def login(request): fbconsole.logout() fbconsole.AUTH_SCOPE = ['read_stream'] fbconsole.authenticate() user = is_user_exists() print user req = get_json_graph_url(api_url = '/me/feed') fb_list = ['id','created_time','updated_time'] while(len(req.json().get('data',''))): for item in req.json()['data']: db_row = [] if item['from']['name']: db_row.append(item['from']['name']) else: db_row.append('') for fb_parse_list in range(len(fb_list)): if item.get(fb_list[fb_parse_list]): db_row.append(item.get(fb_list[fb_parse_list])) else: db_row.append('') time_delta = get_time_delta(ctime=item.get('created_time'),utime=item.get('updated_time')) print time_delta time_delta=str(time_delta) print time_delta try: if item['type'] == 'photo': n = News.objects.create( user=user[0], post_by = db_row[0], post_id = db_row[1], time = db_row[2], updated_time = db_row[3], photo = item["link"], time_delta = time_delta ) else: n = News.objects.create( user=user[0], post_by = db_row[0], post_id = db_row[1], time = db_row[2], updated_time = db_row[3], time_delta = time_delta ) n.save() except: pass if item.has_key('status_type'): if item['status_type']=='shared_story': try: News.objects.filter(post_id__iexact=db_row[1]).update(post_by=item['properties'][0]['text']) News.objects.filter(post_id__iexact=db_row[1]).update(shared='Y') except: pass if item.has_key('comments'): if item.has_key('data'): update_comments_table(n, data = item['comments']['data']) if item.has_key('likes'): if item.has_key('data'): update_likes_table(n, data = item['likes']['data']) next_url = req.json()['paging']['next'] req = requests.get(next_url) fbconsole.logout() return render_to_response('index.html')
def FB_Logout(): fbconsole.logout()