2011-02-04 6 views
0

私はpinCodeが何であるか分かりません。どうすればいいですか? 私はコールバックからそれを得ることができる、前述のように、私は次のコードを見つけた、どのようにできますか?別の方法がある場合は、コードTwitterとoauth-signpostのpinCodeを取得する方法とその方法は?

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(); 

答えて

2

..

を私に示してください、ユーザーがブラウザでauthUrlを訪問しなければなりません。このページでは、アプリケーションに権限を与えて、彼にpinCodeを伝えるように要求します。その後、アプリケーションにpinCodeを入力する必要があります。

このコメントは、これを非常によく説明しています。

+0

どうすればコールバックから取得できますか? – Adham

+1

ユーザにアプリケーションに入力するように伝える必要があります(テキストフィールドなど)。これは自動化できない手動の手順です。 – igorw

+1

必ずしも、コールバックURLを指定すると、承認後に呼び出され、クエリパラメータは検証コードまたはピンになります。 – ldx

関連する問題