Example #1
0
class PyfbTests(unittest.TestCase):

    pyfb_args = {}

    def setUp(self):
        self.pyfb = Pyfb(keys["FACEBOOK_APP_ID"], **self.pyfb_args)
        self.pyfb.set_access_token(keys["FACEBOOK_TOKEN"])
        self.me = self.pyfb.get_myself()

    def test_auth(self):
        self.assertEquals(type(self.me.name), type(unicode()))

    def test_get_friends(self):
        self.assertTrue(isinstance(self.pyfb.get_friends(self.me.id), list))

    def test_get_photos_paging(self):
        photos = self.pyfb.get_photos()
        more_photos = photos.next()
        more_more_photos = more_photos.next()

        if len(photos) < 25 and len(more_photos) > 0:
            raise Exception()

        if len(photos
               ) == 25 and len(more_photos) < 25 and len(more_more_photos) > 0:
            raise Exception()

        self.assertTrue(isinstance(photos, list))
        self.assertTrue(isinstance(more_photos, list))
        self.assertTrue(isinstance(more_more_photos, list))

        self.assertEquals(len(photos), len(more_photos.previous()))
        self.assertEquals(photos.previous(), [])
Example #2
0
class PyfbTests(unittest.TestCase):

    pyfb_args = {}

    def setUp(self):
        self.pyfb = Pyfb(config["FACEBOOK_APP_ID"], **self.pyfb_args)
        self.pyfb.set_access_token(config["FACEBOOK_TOKEN"])
        self.me = self.pyfb.get_myself()

    def test_auth(self):
        self.assertEquals(type(self.me.name), type(unicode()))

    def test_get_friends(self):
        self.assertTrue(isinstance(self.pyfb.get_friends(self.me.id), list))

    def test_get_photos_paging(self):    	
        photos = self.pyfb.get_photos()
        more_photos = photos.next()
        more_more_photos = more_photos.next()

        if len(photos) < 25 and len(more_photos) > 0:
        	raise Exception()
        
        if len(photos) == 25 and len(more_photos) < 25 and len(more_more_photos) > 0:
        	raise Exception()

        self.assertTrue(isinstance(photos, list))
        self.assertTrue(isinstance(more_photos, list))
        self.assertTrue(isinstance(more_more_photos, list))

        self.assertEquals(len(photos), len(more_photos.previous()))
        self.assertEquals(photos.previous(), [])
Example #3
0
def facebook_javascript_login_sucess(request):

    access_token = request.GET.get("access_token")
    # print "printing access token"
    facebook = Pyfb(FACEBOOK_APP_ID)
    facebook.set_access_token(access_token)

    user_id = "https://graph.facebook.com/me?access_token="+str(access_token)
    UID = requests.get(user_id)
    # print UID
    if UID.ok:
        jData = json.loads(UID.content)
        UID = jData['id']

    print str(UID) #print FACEBOOK USER ID
    url = "http://graph.facebook.com/v2.7/"+str(UID)+"/picture?redirect=false"
    print url
    myResponse = requests.get(url)
    print myResponse
    if myResponse.ok:
        jData = json.loads(myResponse.content)
        data = jData['data']
        pic_url = data['url'] #Profile Picture
        print pic_url
    else:
        myResponse.raise_for_status()
        print "error"
    photos = facebook.get_photos()
    print "These are my photos:\n"

    facebook_user = True
    users = User.objects.all()
    me = facebook.get_myself()
    fullname = me.name.split()
    first_name = str(fullname[0])
    last_name = str(fullname[1])
    fullname = first_name + last_name
    if User.objects.filter(username=fullname).exists():
        u = authenticate(username=fullname, password=fullname)
        user_profile = UserProfile.objects.get(user=)
        login(request, u)
        return HttpResponseRedirect('/')
    else:
        return _render_user(facebook, facebook_user, request)
Example #4
0
#http://developers.facebook.com/
FACEBOOK_APP_ID = 'YOUR_APP_ID'

pyfb = Pyfb(FACEBOOK_APP_ID)

#Opens a new browser tab instance and authenticates with the facebook API
#It redirects to an url like http://www.facebook.com/connect/login_success.html#access_token=[access_token]&expires_in=0
pyfb.authenticate()

#Copy the [access_token] and enter it below
token = raw_input("Enter the access_token\n")

#Sets the authentication token
pyfb.set_access_token(token)

photos = pyfb.get_photos()

print "These are my photos:\n"
for photo in photos:
    print photo.picture

#Just call the method next to get the next page of photos!
more_photos = photos.next()

print "\nMore photos:\n"
for photo in more_photos:
    print photo.picture

more_more_photos = more_photos.next()

print "\nDo you want more?:\n"
Example #5
0
#http://developers.facebook.com/
FACEBOOK_APP_ID = 'YOUR_APP_ID'

pyfb = Pyfb(FACEBOOK_APP_ID)

#Opens a new browser tab instance and authenticates with the facebook API
#It redirects to an url like http://www.facebook.com/connect/login_success.html#access_token=[access_token]&expires_in=0
pyfb.authenticate()

#Copy the [access_token] and enter it below
token = raw_input("Enter the access_token\n")

#Sets the authentication token
pyfb.set_access_token(token)

photos = pyfb.get_photos()

print "These are my photos:\n"
for photo in photos:
    print photo.picture

#Just call the method next to get the next page of photos!
more_photos = photos.next()

print "\nMore photos:\n"
for photo in more_photos:
    print photo.picture

more_more_photos = more_photos.next()

print "\nDo you want more?:\n"