首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >什么是以及如何获取Twitter和oauth-signpost的pinCode?

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

Stack Overflow用户
提问于 2011-02-04 23:45:32
回答 1查看 2K关注 0票数 0

我不知道什么是pinCode,我也不知道怎么得到它?!我找到了下面的代码,正如前面提到的,我们可以从CallBack获得它,如何才能呢?如果还有其他方法,请告诉我..

代码

代码语言:javascript
复制
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();
EN

回答 1

Stack Overflow用户

发布于 2011-02-04 23:49:09

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

评论真的很好地描述了这一点。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4899887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档