Share a section of the Tornado Landing Watercress code, only simple implementation of the landing, and did not realize the asynchronous landing. Users who need to make their own code to improve a bit.
Directly on the code:
#coding =utf8import settingsimport urllibfrom Tornado import Httpclientimport JSON class Douban:authurl = ' https://www . douban.com/service/auth2/' User_info_url = ' https://api.douban.com/v2/user/~me ' def Get_authorization_code (self): params = {"client_id": settings.oauth2[' Douban ' [' Key '], "Redirect_uri": settings.oauth2[' Red Irect_url '], "Response_type": "Code", "Scope": "Douban_basic_common",} return Self.auth url+ ' auth? ' +urllib.urlencode (params) def get_access_token (self,code): params = {"client_id": settings.oauth2[' Douban ' [' Key '], "Client_secret": settings.oauth2[' Douban ' [' Sercet '], "Redirect_uri": settings.oauth2 [' Redirect_url '], "Grant_type": "Authorization_code", "Code": Code,} URL = Self.authurl + ' token ' http_client = httpclient. HTTPClient () req = HTTPClient. HttpRequest (url,method= ' POST ', Body=urllib.urlencode (params)) response = Http_client.fetch (req) return Json.loads (response.body) def get_user_info (SE Lf,access_token): url = ' https://api.douban.com/v2/user/~me ' http_client = httpclient. HTTPClient () req = HTTPClient. HttpRequest (url,headers={"Authorization": "Bearer" +access_token}) Response = Http_client.fetch (req) return J Son.loads (Response.body)