예제 #1
0
def facebook_login_success(request):
    code = request.GET.get('code')
    facebook = Pyfb(settings.FACEBOOK_APP_ID)
    facebook.get_access_token(settings.FACEBOOK_SECRET_KEY,
                              code,
                              redirect_uri=settings.FACEBOOK_REDIRECT_URL)
    me = facebook.get_myself()

    try:
        email = InviteEmails.objects.get(emailaddress=me.email)
    except ObjectDoesNotExist:
        emailInstanceCreate(me.email)
        email = InviteEmails.objects.get(emailaddress=me.email)

        return render_to_response(
            'invites/result.html',
            RequestContext(request, {
                'email': email,
                'result': 'success'
            }))
    return render_to_response(
        'invites/result.html',
        RequestContext(request, {
            'email': email,
            'result': 'existing'
        }))
예제 #2
0
def facebook_login_success(request):

    code = request.GET.get('code')

    facebook = Pyfb(FACEBOOK_APP_ID)
    facebook.get_access_token(FACEBOOK_SECRET_KEY, code, redirect_uri=FACEBOOK_REDIRECT_URL)

    return _render_user(facebook)
예제 #3
0
def facebook_login_success(request):

    code = request.GET.get('code')

    facebook = Pyfb(FACEBOOK_APP_ID)
    facebook.get_access_token(FACEBOOK_SECRET_KEY, code, redirect_uri=FACEBOOK_REDIRECT_URL)

    return _render_user(facebook)
예제 #4
0
def facebook_login_success(request):
    code = request.GET.get('code')    
    facebook = Pyfb(FACEBOOK_APP_ID)
    facebook.get_access_token(FACEBOOK_APP_SECRET, code, redirect_uri=FACEBOOK_REDIRECT_URL)
    me = facebook.get_myself()

    welcome = "Welcome %s. Your Facebook login has been completed successfully! Is this your email address? %s"
    return HttpResponse(welcome % (me.name, me.email))
예제 #5
0
파일: views.py 프로젝트: holm/pyfb
def facebook_login_success(request):
    
    code = request.GET.get('code')    

    facebook = Pyfb(FACEBOOK_APP_ID)
    facebook.get_access_token(FACEBOOK_SECRET_KEY, code, redirect_uri=FACEBOOK_REDIRECT_URL)
    me = facebook.get_myself()
    
    welcome = "Welcome <b>%s</b>. Your Facebook login has been completed successfully!"
    return HttpResponse(welcome % me.name)
예제 #6
0
파일: views.py 프로젝트: snahor/pyfb
def facebook_login_success(request):

    code = request.GET.get('code')

    facebook = Pyfb(FACEBOOK_APP_ID)
    facebook.get_access_token(FACEBOOK_SECRET_KEY,
                              code,
                              redirect_uri=FACEBOOK_REDIRECT_URL)
    me = facebook.get_myself()

    welcome = "Welcome <b>%s</b>. Your Facebook login has been completed successfully!"
    return HttpResponse(welcome % me.name)
예제 #7
0
def FacebookLoginSuccess (request):
	code = request.GET.get('code')

	facebook = Pyfb(FACEBOOK_APP_ID)
	facebook.get_access_token(FACEBOOK_SECRET_KEY, code, redirect_uri=FACEBOOK_REDIRECT_URL)
	me = facebook.get_myself()

	if (type(me.name) == type(unicode())):
		return HttpResponse('It worked')

	welcome = "Welcome <b>%s</b>. Your Facebook login has been completed successfully!"
	return HttpResponse(welcome % me.username)
예제 #8
0
파일: views.py 프로젝트: mnive93/lw-1
def facebook_login_success(request):
    code = request.GET.get('code')    
    facebook = Pyfb(settings.FACEBOOK_APP_ID)
    facebook.get_access_token(settings.FACEBOOK_SECRET_KEY, code, redirect_uri=settings.FACEBOOK_REDIRECT_URL)
    me = facebook.get_myself()

    try:
        email = InviteEmails.objects.get(emailaddress = me.email)
    except ObjectDoesNotExist:
        emailInstanceCreate(me.email)
        email = InviteEmails.objects.get(emailaddress = me.email)

        return render_to_response('invites/result.html', RequestContext(request, {'email':email, 'result':'success'}))
    return render_to_response('invites/result.html', RequestContext(request, {'email':email, 'result':'existing'}))
예제 #9
0
def facebook_login_success(request):
    code = request.GET.get('code')
    facebook = Pyfb(FACEBOOK_APP_ID)
    access_token = facebook.get_access_token(FACEBOOK_SECRET_KEY, code, redirect_uri=FACEBOOK_REDIRECT_URL)
    facebook.set_access_token(access_token)
    request.session['access_token'] = access_token
    return render_user(facebook, request)
예제 #10
0
def facebook_login_success(request):
    code = request.GET.get('code')
    facebook = Pyfb(FACEBOOK_APP_ID)
    request.session['tokenFB'] = facebook.get_access_token(FACEBOOK_SECRET_KEY, code,
                                                           redirect_uri=FACEBOOK_REDIRECT_URL)
    user_process(request.session.get('tokenFB'))
    return HttpResponseRedirect(reverse('main.views.manage'))
예제 #11
0
def facebook_login_success(request):
    code = request.GET.get('code')
    facebook = Pyfb(FACEBOOK_APP_ID)
    request.session['tokenFB'] = facebook.get_access_token(
        FACEBOOK_SECRET_KEY, code, redirect_uri=FACEBOOK_REDIRECT_URL)
    user_process(request.session.get('tokenFB'))
    return HttpResponseRedirect(reverse('main.views.manage'))
예제 #12
0
def login(request):
    from datetime import datetime 
    from pyfb import Pyfb
    from NossaCarona.settings import FACEBOOK_APP_ID, FACEBOOK_SECRET_KEY, FACEBOOK_REDIRECT_URL_LOGIN
    if request.GET.get('code'): #Login WITH facebook
        code =  request.GET['code']
        facebook = Pyfb(FACEBOOK_APP_ID)
        facebook.get_access_token(FACEBOOK_SECRET_KEY, code, redirect_uri=FACEBOOK_REDIRECT_URL_LOGIN)
        me = facebook.get_myself()
        userdjango = authenticate(fb_id=me.id)
        if not userdjango:
            userdjango = DjangoUser.objects.create_user(me.email, me.email, None)
            userdjango.first_name = me.first_name
            userdjango.last_name = me.last_name
            userdjango.save()
            usuario = Usuario(user=userdjango, sexo=me.gender[0], fb_id=me.id, dt_nascimento=datetime.strptime(me.birthday,'%m/%d/%Y'))
            usuario.save()
        userlogin(request,userdjango)
    else: #login WITHOUT facebook
        pass
    return HttpResponseRedirect('/')
예제 #13
0
파일: views.py 프로젝트: mnive93/ratatat
def facebooksignupsuccess(request):
    code = request.GET.get('code')    
    facebook = Pyfb(settings.FACEBOOK_APP_ID)
    fb_token = facebook.get_access_token(settings.FACEBOOK_SECRET_KEY, code, redirect_uri=settings.FACEBOOK_SIGNUP_REDIRECT_URL)
    me = facebook.get_myself()

    try:
        user = User.objects.get(email = me.email)
        try:
            fbk = FacebookProfiles.objects.get(user = user)
        except ObjectDoesNotExist:
            fbk = FacebookProfiles.objects.create(
                user = user,
                fbk_id = me.id,
                fbk_token = fb_token
            )

        return HttpResponseRedirect('/auth/login/')
    except ObjectDoesNotExist:
        user = User.objects.create_user(
            username = me.username,
            email = me.email
            )

        fbk = FacebookProfiles.objects.create(
            user = user,
            fbk_id = me.id,
            fbk_token = fb_token
        )

        name_split = shlex.split(me.name)
        fname = name_split[0]
        lname = ''
    
        for x in name_split[1:]:
            lname += (x + ' ')

        user.first_name = fname
        user.last_name = lname
            
        user.save()

        return HttpResponseRedirect('/auth/setpwd/%s' % str(me.id))
예제 #14
0
def facebook_login_success(request):
    code = request.GET.get('code')
    facebook = Pyfb(settings.FACEBOOK_APP_ID)
    access_token = facebook.get_access_token(settings.FACEBOOK_SECRET_KEY, code, redirect_uri=settings.FACEBOOK_REDIRECT_URL)
    me = facebook.get_myself()
     
    #welcome = "Welcome <b>%s</b>. Your Facebook login has been completed successfully!"
    #return HttpResponse(welcome % me.name)
    print access_token
    
    try:
        u=user.objects.get(facebookid=me.id)
        #update access_token
        u.access_token = access_token
        u.save()
    except user.DoesNotExist:
        uhash = make_uuid()
        u = user.objects.create(uhash=uhash, name=me.name,facebookid = me.id, email=me.email, access_token=access_token)

    return render_to_response('mymovies/facebook_login_success.html',{'name':me.name,'uhash':uhash},context_instance=RequestContext(request))
예제 #15
0
def facebook_login_success(request):
    code = request.GET.get('code')
    facebook = Pyfb(settings.CLIENT_ID)
    access_token = facebook.get_access_token(
        settings.CLIENT_APP_SECRET,
        code,
        redirect_uri=settings.REDIRECT_URL
    )
    me = facebook.get_myself()

    try:
        fb_user = FacebookUser.objects.get(email_address=me.email)
        fb_user.access_token = access_token
        fb_user.save()
        user = fb_user.user
    except FacebookUser.DoesNotExist:
        user = User.objects.create(
            username=me.email,
            first_name=me.first_name,
            last_name=me.last_name,
            email=me.email
        )
        user.set_password(me.email)
        user.save()
        fb_user = FacebookUser.objects.create(
            first_name=me.first_name,
            last_name=me.last_name,
            access_token=access_token,
            email_address=me.email,
            username=me.email,
            user=user,
        )

    user = authenticate(
        username=me.email,
        password=me.email
    )
    # log the user in
    login(request, user)
    return HttpResponseRedirect(reverse('blacklist_words'))
예제 #16
0
파일: test.py 프로젝트: snahor/pyfb
from pyfb import Pyfb

FACEBOOK_APP_ID = '248639945152008'
FACEBOOK_SECRET_KEY = "dc9f36b43db5ef243f5ad30152bbe484"
FACEBOOK_REDIRECT_URL = 'http://www.gangaster.com/'

code = "NeFcDl-VwBbLaaPUZJed0uIybGU16qQFCPxUz2yZoAI.eyJpdiI6Ik5HMktDXzJ5ekxtTnpDWFpYc3JJQUEifQ.0_gdyHsesltXUxyOSStmwFj1m7MGm1-ZCkv2AQ5qhkgD_5Q1pjG9LCipfJBBhVqRVrSjCeJH4bf9cI3qGxGAC6rRbcQvwZCj8fEaHM7sbHxSJ-NWPqpIi1ay80XKlF_W"

facebook = Pyfb(FACEBOOK_APP_ID)

#facebook.get_authentication_code()

facebook = Pyfb(FACEBOOK_APP_ID)
facebook.get_access_token(FACEBOOK_SECRET_KEY,
                          code,
                          redirect_uri=FACEBOOK_REDIRECT_URL)
me = facebook.get_myself()

#u = facebook.get_user_by_id()
#facebook.publish("Python Rules!", 1438517184)

#st = facebook.get_statuses()[0]
#print st.message
#print facebook.like(st.id)
#print facebook.get_auth_url

#print facebook.fql_query("SELECT name FROM user WHERE uid = 1438517184")
예제 #17
0
파일: test.py 프로젝트: snahor/pyfb
from pyfb import Pyfb

FACEBOOK_APP_ID = '248639945152008'
FACEBOOK_SECRET_KEY = "dc9f36b43db5ef243f5ad30152bbe484"
FACEBOOK_REDIRECT_URL = 'http://www.gangaster.com/'

code = "NeFcDl-VwBbLaaPUZJed0uIybGU16qQFCPxUz2yZoAI.eyJpdiI6Ik5HMktDXzJ5ekxtTnpDWFpYc3JJQUEifQ.0_gdyHsesltXUxyOSStmwFj1m7MGm1-ZCkv2AQ5qhkgD_5Q1pjG9LCipfJBBhVqRVrSjCeJH4bf9cI3qGxGAC6rRbcQvwZCj8fEaHM7sbHxSJ-NWPqpIi1ay80XKlF_W"

facebook = Pyfb(FACEBOOK_APP_ID)

#facebook.get_authentication_code()

facebook = Pyfb(FACEBOOK_APP_ID)
facebook.get_access_token(FACEBOOK_SECRET_KEY, code, redirect_uri=FACEBOOK_REDIRECT_URL)
me = facebook.get_myself()

#u = facebook.get_user_by_id()
#facebook.publish("Python Rules!", 1438517184)

#st = facebook.get_statuses()[0]
#print st.message
#print facebook.like(st.id) 
#print facebook.get_auth_url

#print facebook.fql_query("SELECT name FROM user WHERE uid = 1438517184")


예제 #18
0
class FacebookAccount:
    """Wrapper for facebook API  """

    def __init__(self):
        self.user = None
        self._user_id = None
        self._access_token = None
        self._api = Pyfb(FACEBOOK_APP_ID)
        self._auth_code = None

    def is_authorized(self):
        """Check if alreade authorized via FB"""
        if self._access_token is None:
            return False
        return True

    def _load_user_info(self):
        """Get out user info"""
        fb_user = self._api.get_myself()
        if fb_user is None:
            return False
        self.user = fb_user.name
        self._user_id = str(fb_user.id)
        return True

    def get_auth_url(self):
        """Return URL for authorization"""
        url = self._api.get_auth_code_url(redirect_uri=FACEBOOK_REDIRECT_URL)
        return url

    def set_auth_code(self, code):
        """Save auth. code returned from FB in case of sucessfull login"""
        self._auth_code = code

    def request_access_token(self):
        """Request access token from FB"""
        self._access_token = self._api.get_access_token(
            FACEBOOK_APP_SECRET, self._auth_code, redirect_uri=FACEBOOK_REDIRECT_URL
        )
        print "FB access token: %s" % self._access_token

    #    def get_extended_at(self, short_lived_access_token):
    #        """Get long time lived access token from short lived."""
    #        from facepy.utils import get_extended_access_token
    #        long_lived_access_token, expires_at = get_extended_access_token(
    #            short_lived_access_token,
    #            FACEBOOK_APP_ID, FACEBOOK_APP_SECRET)
    #        return long_lived_access_token

    def load_messages(self, messages):
        """Load Messages from Twitter"""
        if not self.is_authorized():
            return False
        if self.user is None:
            if not self._load_user_info():
                return False

        print "facebook_access_token=%s" % self._access_token
        url = "https://graph.facebook.com/%s/posts?access_token=%s" % (self._user_id, self._access_token)
        req = urllib2.Request(url)

        try:
            response = urllib2.urlopen(req)
        except ValueError:
            print "Connection Error - Cannot load data from Facebook "
            return False

        # load data to json
        page = response.read()
        fb_data = json.loads(page)
        # print  json.dumps(fb_data,indent=2)
        response.close()

        # Parse loaded data
        msg_count = 0
        for msg in fb_data["data"]:
            text = ""

            # if 'story' field found use it  as a main text to be shown
            if "story" in msg:
                text = msg["story"]

            # Use text from 'message field as a text instead of 'story'
            # if 'message' field exist
            if "message" in msg:  #
                text = msg["message"]

            # create a new message key from timestamp + 'f'
            # where 'f' is added to be unique ('f' means - facebook)
            record_key = str(to_timestamp(msg["created_time"])) + "f"

            # fill out  message with data
            record = {"account": "facebook", "created": to_ctime(msg["created_time"]), "text": text}
            if text.find(" likes") >= 0:
                # Additionally parse url if this is 'like'-message
                picture_id = msg["id"][msg["id"].find("_") + 1 :]
                record["description"] = FB_POST_URL % (self._user_id, picture_id)
                record["link"] = FB_POST_URL % (self._user_id, picture_id)
            if "link" in msg:
                record["link"] = msg["link"]
            if "picture" in msg:
                record["picture"] = msg["picture"]
            if "name" in msg:
                record["name"] = msg["name"]
            if "description" in msg:
                record["description"] = msg["description"]

            # Add new message
            messages[record_key] = record
            msg_count = msg_count + 1
        print "Facebook : %i messages loaded." % msg_count