java - 什么是以及如何获取 Twitter 和 oauth-signpost 的 pinCode?

标签 java api twitter oauth

我不知道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();

最佳答案

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

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

关于java - 什么是以及如何获取 Twitter 和 oauth-signpost 的 pinCode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4899887/

相关文章:

javascript - 在 Selenium 中使用 JavaScriptExecutor 和 Java - 它获取值但不将其显示在字段中

java - 在 java 类中包含自动生成的方法

java - 为二叉搜索树中的每个节点添加路径长度

api - Azure API 管理 OAuth 2.0 资源所有者密码流客户端 ID

rest - GitHub API : how to get total number of accessible repositories

iphone:Facebook 对话框使用 sharekit 立即出现和消失

twitter - TWEEPY 流 : my timeline tweets

java - Maven Java接口(interface)和实现多模块问题

javascript - Laravel 5.0 : Implementation of Notification System(Facebook, Twitter 和 stackoverflow)

android - Google Maps Geocoding API key 使用计数