2

特定のユーザーからの Twitter の応答を表示する Android アプリがあります。API のバージョン 1.1 へのアップグレード以来、OAUTH2 アプリケーションのみの認証を機能させようとしてきましたが、コンシューマー キーとシークレットを送信すると、エラー 400 応答が返されます。

コードは以下のとおりです - どんな助けでも大歓迎です。

HttpClient httpclient = new DefaultHttpClient();
uriString = "https://api.twitter.com/oauth2/token";
HttpPost httppost = new HttpPost(uriString);
HttpParams httpParams = httppost.getParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
HttpConnectionParams.setSoTimeout(httpParams, 15000);

String base64EncodedString =null;
try {
   String encodedConsumerKey = URLEncoder.encode("twitter_consumer_key","UTF-8");
   String encodedConsumerSecret = URLEncoder.encode("twitter_consumer_secret","UTF-8");
   String authString = encodedConsumerKey +":"+encodedConsumerSecret;
   base64EncodedString = Base64.encodeToString(authString.getBytes("UTF-8"), Base64.DEFAULT);
} catch (Exception ex) {
   //do nothing for now...
}

httppost.setHeader(AUTHORIZATION, "Basic " + base64EncodedString);
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
HttpResponse response =null;

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();        
nameValuePairs.add(new BasicNameValuePair("grant_type", "client_credentials"));        
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));        
response = httpclient.execute(httppost);            

statusCode = response.getStatusLine().getStatusCode();
4

1 に答える 1