解析来自重定向URL的信息

问题描述:

我正在使用Hunch API,并试图让用户使用OAuth与我的系统。我指导他们解析来自重定向URL的信息

http://hunch.com/authorize/v1/?app_id=12345&next=http://hoosheer.appspot.com/get-recs

从这个它允许用户输入他们的详细资料,并将其重定向到我的网页。一旦它们被重定向到我的页面,url中包含下列信息。

http://hoosheer.appspot.com/get-recs?auth_token_key=12345abc&user_id=hn_113&next=http://hoosheer.appspot.com/get-recs 

如何从python中获取auth_token_key信息?

谢谢:)

你需要抢解析查询字符串参数出请求的对象。你可以做到这一点的get()这样的:

auth_token_key = request.get('auth_token_key') 

您可以在docs在这读了。

+0

如何访问我在我的代码中重定向到的url。我的代码只是 url ='http://hunch.com/authorize/v1/app_id=X&next=/get-recs' self.redirect(url) 对不起,如果这是一个非常明显的答案,我可以似乎看不到它;) – qwop 2011-01-29 19:26:45

>>> import urlparse 
>>> url = 'http://hoosheer.appspot.com/get-recs?auth_token_key=12345abc&user_id=hn_113&next=http://hoosheer.appspot.com/get-recs' 
>>> parsed = urlparse.urlparse(url) 
>>> urlparse.parse_qs(parsed.query)['auth_token_key'] 
['12345abc'] 
>>>