为什么我会收到此错误:java.lang.IllegalArgumentException:此消费者需要 org.apache.http.HttpRequest 类型的请求
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer (CONSUMER_KEY,CONSUMER_SECRET);
consumer.setTokenWithSecret(oaut_token, tokenSecret);
URL url = new URL(targetURL);
request = (HttpURLConnection) url.openConnection();
// sign the request
consumer.sign(request);
// send the request
request.connect();
编辑: 只需更新已接受的答案,因为它不再相关。路标文档有点过时,由于 HttpURLConnection 上的错误,建议在 Android 中使用 CommonsHttpOAuthConsumer。这些已得到修复,现在 Android 删除了 Apache HTTP,因此现在处理路标的正确方法是通过DefaultOAuthConsumer。
DefaultOAuthConsumer consumer = new DefaultOAuthConsumer (CONSUMER_KEY,CONSUMER_SECRET);
consumer.setTokenWithSecret(oaut_token, tokenSecret);
URL url = new URL(targetURL);
request = (HttpURLConnection) url.openConnection();
// sign the request
consumer.sign(request);