def authenticate(self, token=None, request=None):
        access_token = app_authentication(
            token, settings.FACEBOOK_APP_SETTINGS["APP_ID"],
            settings.FACEBOOK_APP_SETTINGS["APP_SECRET"],
            settings.FACEBOOK_APP_SETTINGS["AUTH_URL"])

        profile = Graph(access_token).get_user()

        try:
            fb_profile = FacebookProfile.objects.get(
                facebook_id=str(profile["id"]))
            fb_profile.access_token = access_token
            fb_profile.save()
            user = fb_profile.user
        except FacebookProfile.DoesNotExist:
            user = User.objects.create(username=profile["id"],
                                       email=profile["email"],
                                       first_name=profile["first_name"],
                                       last_name=profile["last_name"])

            formatted_dob = time.strftime(
                "%Y-%m-%d", time.strptime(profile["birthday"], "%m/%d/%Y"))

            fb_profile = FacebookProfile.objects.create(
                user=user,
                facebook_id=profile["id"],
                access_token=access_token,
                dob=formatted_dob)

        return user
Exemple #2
0
 def albums(self):
     g = Graph(str(self.access_token))
     return g.get_user_albums()
Exemple #3
0
 def friends(self):
     g = Graph(str(self.access_token))
     return g.get_user_friends()
Exemple #4
0
 def albums(self):
     g = Graph(str(self.access_token))
     return g.get_user_albums()
Exemple #5
0
 def friends(self):
     g = Graph(str(self.access_token))
     return g.get_user_friends()