【问题标题】:what is and how to get the pinCode for Twitter and oauth-signpost?什么是以及如何获取 Twitter 和 oauth-signpost 的 pinCode?
【发布时间】:2011-02-04 23:49:08
【问题描述】:

我不知道pinCode 是什么,我也不知道如何得到它?! 我找到了以下代码,如前所述,我们可以从 CallBack 中获取它,怎么能?如果有其他方法请告诉我..

代码

OAuthConsumer consumer = new DefaultOAuthConsumer(
                // the consumer key of this app (replace this with yours)
                "iIlNngv1KdV6XzNYkoLA",
                // the consumer secret of this app (replace this with yours)
                "exQ94pBpLXFcyttvLoxU2nrktThrlsj580zjYzmoM");

        OAuthProvider provider = new DefaultOAuthProvider(
                "http://twitter.com/oauth/request_token",
                "http://twitter.com/oauth/access_token",
                "http://twitter.com/oauth/authorize");

        /****************************************************
         * The following steps should only be performed ONCE
         ***************************************************/

        // we do not support callbacks, thus pass OOB
        String authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);

        // bring the user to authUrl, e.g. open a web browser and note the PIN code
        // ...         

        String pinCode = // ... you have to ask this from the user, or obtain it
        // from the callback if you didn't do an out of band request

        // user must have granted authorization at this point
        provider.retrieveAccessToken(consumer, pinCode);

        // store consumer.getToken() and consumer.getTokenSecret(),
        // for the current user, e.g. in a relational database
        // or a flat file
        // ...

        /****************************************************
         * The following steps are performed everytime you
         * send a request accessing a resource on Twitter
         ***************************************************/

        // if not yet done, load the token and token secret for
        // the current user and set them
        consumer.setTokenWithSecret(ACCESS_TOKEN, TOKEN_SECRET);

        // create a request that requires authentication
        URL url = new URL("http://twitter.com/statuses/mentions.xml");
        HttpURLConnection request = (HttpURLConnection) url.openConnection();

        // sign the request
        consumer.sign(request);

        // send the request
        request.connect();

        // response status should be 200 OK
        int statusCode = request.getResponseCode();

【问题讨论】:

    标签: java api twitter oauth


    【解决方案1】:

    用户必须在浏览器中访问 authUrl。该页面将要求他授权应用程序,然后告诉他密码。然后他必须将 pinCode 输入到您的应用程序中。

    cmets 确实很好地描述了这一点。

    【讨论】:

    • 如何从回调中获取?
    • 您需要告诉用户将其输入到您的应用程序中,例如通过文本字段。这是一个无法自动化的手动步骤。
    • 不一定,如果你提供回调URL,授权后会调用,查询参数为验证码或pin。
    猜你喜欢
    • 2014-01-22
    • 2011-05-03
    • 1970-01-01
    • 2010-12-31
    • 2013-01-14
    • 2011-08-29
    • 2011-07-03
    • 1970-01-01
    • 2011-12-12
    相关资源
    最近更新 更多