当前位置: 首页>>代码示例>>Python>>正文


Python FacebookAuthorization.extend_access_token方法代码示例

本文整理汇总了Python中open_facebook.FacebookAuthorization.extend_access_token方法的典型用法代码示例。如果您正苦于以下问题:Python FacebookAuthorization.extend_access_token方法的具体用法?Python FacebookAuthorization.extend_access_token怎么用?Python FacebookAuthorization.extend_access_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在open_facebook.FacebookAuthorization的用法示例。


在下文中一共展示了FacebookAuthorization.extend_access_token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: registered_facebook

# 需要导入模块: from open_facebook import FacebookAuthorization [as 别名]
# 或者: from open_facebook.FacebookAuthorization import extend_access_token [as 别名]
def registered_facebook(request):
    global token
    social_account = None
    username = ''
    try:
        token = request.POST.get('access_token')
        long_access_token = FacebookAuthorization.extend_access_token(token)['access_token']
        print 'long is generated'
        print long_access_token
    except Exception as e:
        print e
        print "register 1"
        long_access_token = token
        print long_access_token

    try:
        graph = OpenFacebook(long_access_token)
        profile = graph.get('me')
        profile_id = profile['id']
        # profile_email = profile['email']
        profile_first_name = profile['first_name']
        profile_last_name = profile['last_name']

        profile_gender = profile['gender']
        if profile_gender == 'male':
            sex = True
        else:
            sex = False
    except Exception as e:
        print '%s (%s)' % (e.message, type(e))
        return HttpResponseRedirect('/sorry/')

    try:
        print "1212122asas"
        social_account = SocialData.objects.filter(account_id=str(profile_id)).all()
        print social_account
        print "1"
    except Exception as e:
        print "HATA" + e

    try:
        print "sss"
        print "r4"
        if social_account:
            print "hesap var"
            user = User.objects.get(id=social_account[0].user.id)
            social_network = SocialData.objects.get(user=user.id)
            username = str(user.username)
            password = str(user.password)
            social_network.account_token = long_access_token
            print username
            print password
            print "sss"
        else:
            print "Hesap yok"
            user_auth = User.objects.create_user(profile_id, 'sss', profile_id)
            user_auth.first_name = profile_first_name
            user_auth.last_name = profile_last_name
            print "sss"
            user_auth.email = ""
            user_auth.is_staff = False
            user_auth.is_active = True
            user_auth.save()
            print "user kayit oldu"
            au = Audience.objects.get(id=1)
            users = Users.objects.create(user_id=user_auth.id, gender=sex, been_id=1, lives_in_id=1)
            users.save()
            print "users kayit oldu"
            social_network = SocialData(user=user_auth, account_type=0, account_id=profile_id,
                                        account_token=long_access_token)
            username = profile_id
        social_network.save()
        dada = authenticate(username=username, password=username)
        if dada is not None:
            print "ac"
            if dada.is_active:
                print "ba"
                auth_login(request, dada)
                print "you are login !!!" + "hello " + request.user.username
                return HttpResponse("true", content_type='application/json')
        else:
            print "b"
        print "a"
        print "social_network kayıt oldu"
        return "false"
    except Exception as e:
        print e
        print "register4"
        return HttpResponseRedirect('/login/')
开发者ID:mkaykisiz,项目名称:owl_survey,代码行数:91,代码来源:views.py


注:本文中的open_facebook.FacebookAuthorization.extend_access_token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。