本文介绍了python oauth 2.0新的fbsr facebook cookie,错误验证验证码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我尝试使用新的fbsr _ {{appID}} cookie。 我使用以下函数来解析它,但是当我尝试之后得到access_token,我得到'错误验证验证码'消息。这些解析函数有问题吗?如果没有,可能是什么问题? 更多信息:我设法使用oauth链接登录用户而不使用cookie,oauth链接重定向到我的网站该代码作为参数,因此它不能是应用程序ID,应用程序秘密或redirect_uri。另一个原因是这些错误消息不同。 def base64_url_decode(inp): padding_factor =(4 - len (inp)%4)%4 inp + ==* padding_factor return base64.b64decode(unicode(inp).translate(dict(zip(map(ord,u'-_')) ,u'+ /')))) def parse_signed_request(signed_request,secret): l = signed_request.split('。',2) encoded_sig = 1 [0] payload = 1 [1] sig = base64_url_decode(encoded_sig) data = json.loads(base64_url_decode(payload)) if data.get('algorithm')。upper()!='HMAC-SHA256': logging.error('未知算法')返回无 else: expected_sig = hmac.new(secret,msg =有效载荷,digestmod = hashlib.sha256).digest() $ b $如果sig!= expected_sig:返回无 else: logging.debug('收到的有效签名请求')返回数据 args = {} args ['client_id'] = fbapp_id args ['redirect_uri'] = site_url args ['client_secret'] = fbapp_secret args ['code'] = code response = urllib.urlopen('https://graph.facebook.com/oauth/access_token?'+urllib.urlencode(args))#。 ..在这里我从服务器收到错误:错误验证验证码... 解决方案有一个facebook python SDK的修改版本,它支持OAuth 2.0和解析github上的fbsr_ cookie: https://gist.github.com/1190267 你可以看看进入代码,看看如何解析cookie或只是让这个文件为你做的工作。 I'm trying to use the new fbsr_{{appID}} cookie.I'm using the following functions to parse it, but when I try to get the access_token afterwards, I get 'error validating verification code' message. Is something wrong with these parsing functions? If not, what could be the problem?more info:I managed to log users in without cookies using the oauth link which redirects back into my site with the code as a parameter, so it can't be the app id, app secret or the redirect_uri. Another reason is that these have different error messages.def base64_url_decode(inp): padding_factor = (4 - len(inp) % 4) % 4 inp += "="*padding_factor return base64.b64decode(unicode(inp).translate(dict(zip(map(ord, u'-_'), u'+/'))))def parse_signed_request(signed_request, secret): l = signed_request.split('.', 2) encoded_sig = l[0] payload = l[1] sig = base64_url_decode(encoded_sig) data = json.loads(base64_url_decode(payload)) if data.get('algorithm').upper() != 'HMAC-SHA256': logging.error('Unknown algorithm') return None else: expected_sig = hmac.new(secret, msg=payload, digestmod=hashlib.sha256).digest() if sig != expected_sig: return None else: logging.debug('valid signed request received..') return dataargs = {}args['client_id'] = fbapp_idargs['redirect_uri'] = site_urlargs['client_secret'] = fbapp_secretargs['code'] = coderesponse = urllib.urlopen('https://graph.facebook.com/oauth/access_token?'+urllib.urlencode(args))# ... here i'm getting the error back from the server: error validating verification code... 解决方案 There is a modified version of the facebook python SDK which supports OAuth 2.0 and parsing of the fbsr_ cookie on github here:https://gist.github.com/1190267You can look into the code to see how to parse the cookie or just let that file do the work for you. 这篇关于python oauth 2.0新的fbsr facebook cookie,错误验证验证码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS!
05-22 14:50
查看更多