def get(self): user = users.get_current_user() if not user: self.redirect(users.create_login_url(self.request.uri)) return oauth_token = self.request.get('oauth_token') oauth_verifier = self.request.get('oauth_verifier') user_model = UserModel.get_or_new(user) if user_model.twit_token.token_key != oauth_token: raise Exception() token = user_model.twit_token.to_oauth2() token.set_verifier(oauth_verifier) client = ClientBase(self.consumer, token) resp, content = client.request(TWIT_ACCESS_TOKEN_URL, "POST") if resp['status'] != '200': raise Exception() result = dict(parse_qsl(content)) user_model.set_twit_token( Token( token_key=result['oauth_token'], token_secret=result['oauth_token_secret'], is_access_token=True ) ) user_model.refresh_last_twit_id() user_model.update_processed() self.redirect('/')
def get(self): user = users.get_current_user() if not user: self.redirect(users.create_login_url(self.request.uri)) return oauth_token = self.request.get('oauth_token') oauth_verifier = self.request.get('oauth_verifier') user_model = UserModel.get_or_new(user) if user_model.town_token.token_key != oauth_token: raise Exception() token = user_model.town_token.to_oauth2() token.set_verifier(oauth_verifier) client = ClientBase(self.consumer, token) resp, content = client.request(TOWN_ACCESS_TOKEN_URL, "POST") if resp['status'] != '200': raise Exception() result = dict(parse_qsl(content)) user_model.set_town_token( Token( token_key=result['oauth_token'], token_secret=result['oauth_token_secret'], is_access_token=True ) ) me = get_town_me(user_model.town_token) if me: entrance_year = (me['entrance_year'] % 100) user_model.town_board_id = "board_alumni%02d" % entrance_year user_model.put() self.redirect('/')
def get_request_token(service): client = ClientBase(service['consumer']) client.set_callback(service['callback']) resp, content = client.request(service['request_token_url'], "POST") if resp['status'] != '200': raise Exception() result = dict(parse_qsl(content)) return result
def signget(service, token, uri): client = ClientBase(service['consumer'], token) return client.request(uri, "GET")
def signpost(service, token, uri, body): client = ClientBase(service['consumer'], token) return client.request(uri, "POST", body)