'Complete oauth: take tokens from session + pin from form,
and do the 2nd API call to Twitter'

@staticmethod
def twitter_channel_onvalidation(form):

    T = current.T
    session = current.session
    settings = current.deployment_settings.msg
    s3 = session.s3
    form_vars = form.vars
    if (form_vars.pin and s3.twitter_request_key and s3.twitter_request_secret):
        try:
            import tweepy
        except:
            raise HTTP(501, body=T("Can't    import    tweepy"))
        oauth = tweepy.OAuthHandler(settings.twitter_oauth_consumer_key, settings.twitter_oauth_consumer_secret)
        oauth.set_request_token(s3.twitter_request_key, s3.twitter_request_secret)
        try:
            oauth.get_access_token(form_vars.pin)
            form_vars.oauth_key = oauth.access_token.key
            form_vars.oauth_secret = oauth.access_token.secret
            twitter = tweepy.API(oauth)
            form_vars.twitter_account = twitter.me().screen_name
            form_vars.pin = ''
            return
        except tweepy.TweepError:
            session.error = T('Settings    were    reset    because    authenticating    with    Twitter    failed')
    for k in ['oauth_key', 'oauth_secret', 'twitter_account']:
        form_vars[k] = None
    for k in ['twitter_request_key', 'twitter_request_secret']:
        s3[k] = ''
