Exemplo n.º 1
0
def desktop_app():
    from facebook import Facebook

    # Get api_key and secret_key from a file
    fbs = open(FB_SETTINGS).readlines()
    facebook = Facebook(fbs[0].strip(), fbs[1].strip())

    facebook.auth.createToken()
    # Show login window
    facebook.login()

    # Login to the window, then press enter
    print 'After logging in, press enter...'
    raw_input()

    facebook.auth.getSession()
    info = facebook.users.getInfo([facebook.uid], ['name', 'birthday', 'affiliations', 'sex'])[0]

    for attr in info:
        print '%s: %s' % (attr, info[attr])

    friends = facebook.friends.get()
    friends = facebook.users.getInfo(friends[0:5], ['name', 'birthday', 'relationship_status'])

    for friend in friends:
        if 'birthday' in friend:
            print friend['name'], 'has a birthday on', friend['birthday'], 'and is', friend['relationship_status']
        else:
            print friend['name'], 'has no birthday and is', friend['relationship_status']

    arefriends = facebook.friends.areFriends([friends[0]['uid']], [friends[1]['uid']])

    photos = facebook.photos.getAlbums(friends[1]['uid'])
    print photos
def app():
    from facebook import Facebook
    
    #Get api key and secret key 
    facebook=Facebook(API_KEY, API_SECRET)
    
    facebook.auth.createToken()
    #Show login window
    facebook.login()
    
    #Log in to the window and then press enter    
    print "After you log in, press enter"
    raw_input()
    
    facebook.request_extended_permission('friends_birthday')
    raw_input()
    
    
    
    facebook.auth.getSession()
    info = facebook.users.getInfo([facebook.uid], ['name', 'birthday'])[0]
    print info
    
    for attr in info:
        print '%s: %s' % (attr, info[attr])

    friends = facebook.friends.get()
    friends = facebook.users.getInfo(friends[0:100], ['name', 'birthday'])

    for friend in friends:
        if friend['birthday'] is not None:
            print friend['name'], 'has a birthday on', friend['birthday']
        else:
            print friend['name'], 'has no birthday'
Exemplo n.º 3
0
 def _start_fb_session(self):
     api_key = settings.FACEBOOK_API_KEY
     secret_key = settings.FACEBOOK_SECRET_KEY
     app_name = getattr(settings, 'FACEBOOK_APP_NAME', None)
     callback_path = getattr(settings, 'FACEBOOK_CALLBACK_PATH', None)
     internal = getattr(settings, 'FACEBOOK_INTERNAL', True)
     proxy = getattr(settings, 'HTTP_PROXY', None)
     facebook = Facebook(api_key,
                         secret_key,
                         app_name=app_name,
                         internal=internal,
                         callback_path=callback_path,
                         proxy=proxy)
     facebook.auth.createToken()
     # Show login window
     # Set popup=True if you want login without navigational elements
     facebook.login()
     # Login to the window, then press enter
     print 'After logging in, press enter...'
     raw_input()
     facebook.auth.getSession()
     print 'Session Key:   ', facebook.session_key
     print 'Your UID:      ', facebook.uid
     info = facebook.users.getInfo(
         [facebook.uid], ['name', 'birthday', 'affiliations', 'sex'])[0]
     print 'Hi ', info['name']
     return facebook
Exemplo n.º 4
0
def app():
    from facebook import Facebook

    #Get api key and secret key
    facebook = Facebook(API_KEY, API_SECRET)

    facebook.auth.createToken()
    #Show login window
    facebook.login()

    #Log in to the window and then press enter
    print "After you log in, press enter"
    raw_input()

    facebook.request_extended_permission('friends_birthday')
    raw_input()

    facebook.auth.getSession()
    info = facebook.users.getInfo([facebook.uid], ['name', 'birthday'])[0]
    print info

    for attr in info:
        print '%s: %s' % (attr, info[attr])

    friends = facebook.friends.get()
    friends = facebook.users.getInfo(friends[0:100], ['name', 'birthday'])

    for friend in friends:
        if friend['birthday'] is not None:
            print friend['name'], 'has a birthday on', friend['birthday']
        else:
            print friend['name'], 'has no birthday'
def fbLogin():
    from facebook import Facebook
    facebook = Facebook(API,SECRET)
    facebook.auth.createToken()
    facebook.login()
    facebook.auth.getSession()
    return facebook
Exemplo n.º 6
0
	def connect(self, api_key, secret_key):
		facebook = Facebook(api_key, secret_key)
		facebook.auth.createToken()
		facebook.login()
		print "After logging in, press enter..."
		raw_input()
		facebook.auth.getSession()
Exemplo n.º 7
0
def desktop_app():

    userdata = {}

    apiattr = ['uid', 'name', 'about_me', 'activities', 'birthday_date', 'relationship_status',
            'books', 'current_location', 'email_hashes', 'first_name', 'hometown_location',
            'hs_info', 'interests', 'last_name', 'locale', 'meeting_for', 'meeting_sex',
            'movies', 'music', 'notes_count', 'notes_count', 'pic_with_logo', 'pic_big',
            'pic_big_with_logo','pic_small','pic_small_with_logo','pic_square','pic_square_with_logo',
            'political','profile_blurb','profile_update_time','profile_url','proxied_email',
            'quotes','religion','sex','significant_other_id','status','timezone','tv','username',
            'username','wall_count','website','work_history',
            'education_history', 'affiliations']

    # Get api_key and secret_key from a file
    homedir = os.path.expanduser('~')
    fbs = open(homedir + '/.fbkeys').readlines()
    facebook = Facebook(fbs[0].strip(), fbs[1].strip())

    file = open('fbdat_1.txt', 'w')

    facebook.auth.createToken()
    # Show login window
    facebook.login()
    wait_login()                # somehow wait for the user to log in

    # Login to the window, then press enter
    #print 'After logging in, press enter...'
    #raw_input()

    facebook.auth.getSession()
    info = facebook.users.getInfo([facebook.uid], ['name', 'birthday', 'affiliations', 'sex'])[0]

    for attr in info:
        print '%s: %s' % (attr, info[attr])

    friends = facebook.friends.get()
    print friends

    dat = facebook.users.getInfo(friends,apiattr)
    print '################################ DAT #########################'
    print dat


    for da in dat: # put to dict
        userdata[da[u'uid']] = da

    print '################################ USERDATA ####################'
    print userdata
    pickle.dump(userdata, file)

##    for user in userdata:
##        #if not user.haskey(u'uid'):
##        s = str(userdata[user])
##        sd = s.encode(output_encoding)
##        file.write(sd)


    file.close()
    exit()
Exemplo n.º 8
0
def facebook_init():
    facebook = Facebook(API_KEY, SECRET)

    facebook.auth.createToken()
    facebook.login()

    print 'After logging in, press any key...'
    raw_input()

    facebook.auth.getSession()
    return facebook
    def open(self):
        """
        Opens connection to facebook.
        """
        from facebook import Facebook
        super(facebook_connector, self).open()
        facebook = Facebook(api_key=self.api_key, secret_key=self.secret_key)
        auth_token = facebook.auth.createToken()
        facebook.login(self.email)

        time.sleep(self.delay_time)
        session = facebook.auth.getSession()
        return facebook
    def open(self):
        """
        Opens connection to facebook.
        """
        from facebook import Facebook
        super(facebook_connector, self).open()
        facebook = Facebook(api_key=self.api_key, secret_key=self.secret_key)
        auth_token = facebook.auth.createToken()
        facebook.login(self.email)

        time.sleep(self.delay_time)
        session = facebook.auth.getSession()
        return facebook
Exemplo n.º 11
0
def facebook_download(outDir, fb_uid = None):

    # out dir setup
    if exists(outDir):
        rmtree(outDir)
    os.makedirs(outDir)
 
    # Get api_key and secret_key from a file
    # first line is api key and second line is secret
    fbs = open('/tmp/facebook_keys.txt').readlines()
    facebook = Facebook(fbs[0].strip(), fbs[1].strip())
 
    facebook.auth.createToken()
    # Show login window
    facebook.login()
 
    # Login to the window, then press enter
    print 'After logging in, press enter...'
    raw_input()
 
    facebook.auth.getSession()
 
    # PHOTOS
    # By album ID
    # photos = facebook.photos.getAlbums(friends[1]['uid'])
    # photos = facebook.photos.get('', '5307080636404757', '')

    friends = facebook.friends.get()
    names = facebook.users.getInfo(friends, ['name'])
    for n in names:
        print n['name'].encode('utf-8'), ':', n['uid']

    # By user id
    if fb_uid is None:
        fb_uid = facebook.uid
    photos = facebook.photos.get(fb_uid)

    progress = ProgressMsg(len(photos), output=sys.stderr)
    for p in photos:
        url = p['src_big']
        fn = url.split('/')[-1]
        fd = open(join(outDir, fn), 'w')

        import urllib
        bytes = urllib.urlopen(url).read()
        fd.write(bytes)
        fd.close()

        progress.Increment()
Exemplo n.º 12
0
def desktop_app():

    # Get api_key and secret_key from a file
    fbs = open(FB_SETTINGS).readlines()
    facebook = Facebook(fbs[0].strip(), fbs[1].strip())

    facebook.auth.createToken()
    # Show login window
    facebook.login()

    # Login to the window, then press enter
    #print 'After logging in, press enter...'
    #raw_input()

    facebook.auth.getSession()
    return facebook
Exemplo n.º 13
0
class Shazam(object):
    """
    Provides methods for downloading Shazam history
    """

    def __init__(self, fb_email=None, fb_password=None):
        self.session = Ghost().start()
        self.facebook = Facebook(self.session, fb_email, fb_password)
        self.login_successful = False
        self.fat = None # Facebook access token

    def login(self):
        """
        Performs Shazam login
        :return: bool - True if success, False - otherwise
        """

        if self.login_successful:
            return True

        if not self.facebook.login():
            return False

        # fat = self.facebook.get_access_token(app_id)
        # if not fat:
        #     logging.error("Couldn't get Facebook access token")
        #     return False
        #
        # user_id = self.facebook.get_user_id()
        # if not user_id:
        #     logging.error("Couldn't get Facebook user id")
        #     return False
        #
        # query = [("fat", fat),
        #          ("uid", user_id)]
        # body = urllib.urlencode(query)
        # login_url = "http://www.shazam.com/login"
        # try:
        #     self.session.open(login_url,
        #                       method="post",
        #                       body=body)
        # except Exception, e:
        #     logging.error("Shazam login failed")
        #     logging.error(str(e))
        #     return False
        myshazam_url = "http://www.shazam.com/myshazam"
        try:
            self.session.open(myshazam_url)
        except Exception, e:
            logging.error("Shazam login failed. Couldn't open myshazam page.")
            logging.error(str(e))
            return False
        try:
            self.session.click(".js-fblogin")
        except Exception, e:
            logging.error("Shazam login failed. Couldn't click login button.")
            logging.error(str(e))
            return False
Exemplo n.º 14
0
class Shazam(object):
    """
    Provides methods for downloading Shazam history
    """
    def __init__(self, fb_email=None, fb_password=None):
        self.session = Ghost().start()
        self.facebook = Facebook(self.session, fb_email, fb_password)
        self.login_successful = False
        self.fat = None  # Facebook access token

    def login(self):
        """
        Performs Shazam login
        :return: bool - True if success, False - otherwise
        """

        if self.login_successful:
            return True

        if not self.facebook.login():
            return False

        # fat = self.facebook.get_access_token(app_id)
        # if not fat:
        #     logging.error("Couldn't get Facebook access token")
        #     return False
        #
        # user_id = self.facebook.get_user_id()
        # if not user_id:
        #     logging.error("Couldn't get Facebook user id")
        #     return False
        #
        # query = [("fat", fat),
        #          ("uid", user_id)]
        # body = urllib.urlencode(query)
        # login_url = "http://www.shazam.com/login"
        # try:
        #     self.session.open(login_url,
        #                       method="post",
        #                       body=body)
        # except Exception, e:
        #     logging.error("Shazam login failed")
        #     logging.error(str(e))
        #     return False
        myshazam_url = "http://www.shazam.com/myshazam"
        try:
            self.session.open(myshazam_url)
        except Exception, e:
            logging.error("Shazam login failed. Couldn't open myshazam page.")
            logging.error(str(e))
            return False
        try:
            self.session.click(".js-fblogin")
        except Exception, e:
            logging.error("Shazam login failed. Couldn't click login button.")
            logging.error(str(e))
            return False
Exemplo n.º 15
0
def main():
    if args.twitter:
        t = Twitter(args)
        t.login()
        t.get_tweepy_API()
        if args.command == 'read':
            t.read()
        elif args.command == 'post':
            t.post()
        else:
            t.delete()
 
    if args.facebook:
        f = Facebook(args)
        f.login()
        f.get_facepy_API()
        if args.command == 'read':
            f.read()
        elif args.command == 'post':
            f.post()
        else:
            f.delete()
Exemplo n.º 16
0
 def _start_fb_session(self):
     api_key = settings.FACEBOOK_API_KEY
     secret_key = settings.FACEBOOK_SECRET_KEY
     app_name = getattr(settings, 'FACEBOOK_APP_NAME', None)
     callback_path = getattr(settings, 'FACEBOOK_CALLBACK_PATH', None)
     internal = getattr(settings, 'FACEBOOK_INTERNAL', True)
     proxy = getattr(settings, 'HTTP_PROXY', None)
     facebook = Facebook(api_key, secret_key, app_name=app_name,
                         internal=internal, callback_path=callback_path,
                         proxy=proxy)
     facebook.auth.createToken()
     # Show login window
     # Set popup=True if you want login without navigational elements
     facebook.login()
     # Login to the window, then press enter
     print 'After logging in, press enter...'
     raw_input()
     facebook.auth.getSession()
     print 'Session Key:   ', facebook.session_key
     print 'Your UID:      ', facebook.uid
     info = facebook.users.getInfo([facebook.uid], ['name', 'birthday', 'affiliations', 'sex'])[0]
     print 'Hi ', info['name']
     return facebook
Exemplo n.º 17
0
class TestFacebook(unittest.TestCase):
    def setUp(self):
        # simulate "psh -f read" command args
        args = Namespace(cargs='home', command='read', facebook=True, media='', number=10, status='', twitter=False, verbose=False)
        self.f = Facebook(args)
        self.f.login()

    def test_login(self):
        # Tests login() & indirectly, known_user_auth()
        # and first_time_auth() by checking the access
        # token of 'self.auth'

        # read in access token from 'facebook-access-token.txt'
        with open('facebook-access-token.txt', 'r') as infile:
            content = infile.readlines()
        access_token = content[0].rstrip()
        access_token_secret = content[1].rstrip()
        self.assertEqual(self.f.auth.access_token, access_token)
        self.assertEqual(self.f.auth.access_token_secret, access_token_secret)

    def test_get_facepy_API(self):
        # Tests get_facepy_API & verify() indirectly

        self.assertFalse(isinstance(self.f.api, facepy.API))
        self.f.get_facepy_API()
        self.assertTrue(isinstance(self.f.api, facepy.API))

    def test_statuses_to_tweets(self):
        self.t.get_tweepy_API()
        statuses = self.t.api.home_timeline(count=self.t.args.number)
        tweets = self.t.statuses_to_tweets(statuses)
        # check first element, assume the rest are the same
        self.assertTrue(isinstance(tweets[0], tweet.Tweet))

        tweets = self.t.statuses_to_tweets([])
        self.assertFalse(tweets)
Exemplo n.º 18
0
import os, sys, optparse, time, json
import webbrowser
import pynotify
import urllib
home = os.getenv("HOME")+unicode("/.faccialibro/")
file_session = open(unicode(home)+unicode("faccialibro.session"),"r")
session_read = file_session.read()
file_session.close()
if file_session:
    session_read = session_read
else:
    session_read = ""
if session_read == "":
    fb = Facebook('261918900490462', 'c2bb3994ddcd0078e33bc9fb63daa434')
    fb.auth.createToken()
    fb.login(popup=True)
    session = fb.auth.getSession()
    webbrowser.open('http://m.facebook.com/login.php?app_id=261918900490462&cancel=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&fbconnect=1&next=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Fuiserver.php%3Fmethod%3Dpermissions.request%26app_id%3D261918900490462%26display%3Dwap%26redirect_uri%3Dhttp%253A%252F%252Fwww.facebook.com%252Fconnect%252Flogin_success.html%26locale%3Dit_IT%26perms%3Duser_photos%26fbconnect%3D1%26from_login%3D1&rcount=1&locale2=it_IT&_rdr',new=2)
    file_session_write = open(unicode(home)+unicode("faccialibro.session"),"w+")
    file_session_write.write(session['session_key'])
    file_session_write.close()
    file_uid_write = open(unicode(home)+unicode("faccialibro.user-id"),"w+")
    file_uid_write.write(str(session['uid']))
    file_uid_write.close()
    file_secret_write = open(unicode(home)+unicode("faccialibro.secret"),"w+")
    file_secret_write.write(str(session['secret']))
    file_secret_write.close()
else:
    file_uid = open(unicode(home)+unicode("faccialibro.user-id"),"r")
    uid_read = file_uid.read()
    file_uid.close()
Exemplo n.º 19
0
# Open file corresponding to the TUN device.
tun = open('/dev/net/tun', 'r+b')
ifr = struct.pack('16sH', 'tun0', IFF_TUN | IFF_NO_PI)
fcntl.ioctl(tun, TUNSETIFF, ifr)
fcntl.ioctl(tun, TUNSETOWNER, 1000)

if not (len(sys.argv) == 2 and (sys.argv[1] == 'client'
                             or sys.argv[1] == 'server')):
    print "Use: python linux_client.py [client|server]"
    exit()

# Log in to facebook
(email,password) = file("creds.txt").read().split()
fb = Facebook("cache.txt")
login_ok = fb.login(email, password)

if not login_ok:
    print "login failed, exit"
    exit(1)

mode = sys.argv[1]
# Bring it up and assign addresses.
if( mode == 'client' ):
    subprocess.check_call('ifconfig tun0 '+client_ip+' pointopoint '+server_ip+' up',
        shell=True)
else:
    subprocess.check_call('ifconfig tun0 '+server_ip+' pointopoint '+client_ip+' up',
        shell=True)

while True:
Exemplo n.º 20
0
facebook = Facebook(fbs[0].strip(), fbs[1].strip())

while True:
	print strftime("%a, %d %b %Y %H:%M:%S", localtime())
	try:
		session = load(file(".session"))
		print session
		facebook.secret = session['secret']
		facebook.session_key = session['session_key']
		facebook.session_key_expires = session['expires']
		facebook.uid = session['uid']
	except (EOFError,IOError):
		token = facebook.auth.createToken()
		print "token",facebook.auth._client.auth_token
		# Show login window
		facebook.login()

		# Login to the window, then press enter
		print 'After logging in, press enter...'
		raw_input()
		res = facebook.auth.getSession()
		dump(res,file(".session","w"))

	try:
		data = parse(urlopen("http://twitter.com/statuses/user_timeline/palfrey.xml"))

		laststatus = data.getElementsByTagName("text")[0].firstChild.data

		status = facebook.fql.query("select status from user where uid=%s"%facebook.uid)[0]['status']['message']
		if len(status)>140:
			status = status[:136]+" ..."